Code review and fixes.
This commit is contained in:
1 parent
b51a08e7cc
commit
f9aa0dabed
9 files changed
+58
-20
No files matched your search
+1
-1
@@ -37,7 +37,7 @@ add_custom_command(OUTPUT "${menu_hook32}" "${menu_host32}"
|
||||
COMMAND "${MINGW32_C_COMPILER}" -std=c11 -O2 -Wall -Wextra -mwindows
|
||||
-static-libgcc -o "${menu_host32}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/menu_host32.c" -luser32
|
||||
DEPENDS menu_hook.c menu_bridge.h notification_hook.c notification_hook.h bootstrapper_hook.c bootstrapper_hook.h menu_host32.c foreground_hooks.h edit_hook.c edit_hook.h control_class.h
|
||||
DEPENDS menu_hook.c menu_bridge.h notification_hook.c notification_hook.h bootstrapper_hook.c bootstrapper_hook.h menu_host32.c foreground_hooks.h hook_exclusions.h edit_hook.c edit_hook.h control_class.h
|
||||
VERBATIM)
|
||||
add_custom_target(wine-access-menu32 ALL DEPENDS "${menu_hook32}" "${menu_host32}")
|
||||
|
||||
|
||||
@@ -302,6 +302,8 @@ never hook or dialog-read, while still serving their controller speech;
|
||||
readers use them for games whose anti-tamper code objects to injected hooks,
|
||||
so the protection holds from the helper's first foreground poll rather than
|
||||
only after the reader's next supervision pass.
|
||||
Invalid or missing executable names and lists exceeding 256 unique names
|
||||
cause startup to fail before hooks are installed. Names may contain semicolons.
|
||||
|
||||
Review retains the shared `/org/stormux/Cthulhu1/WineReview` object path and
|
||||
`org.stormux.Cthulhu1.WineReview` interface for both readers. Use the helper's
|
||||
|
||||
+4
-3
@@ -5,9 +5,10 @@
|
||||
// Programs whose threads must never receive the native menu/input hooks,
|
||||
// named by executable file name. Readers pass one --exclude-hook-program
|
||||
// argument per program; the 64-bit helper forwards the same list to the
|
||||
// 32-bit hook host through WINE_ACCESS_EXCLUDE_HOOK_PROGRAMS (';'-joined),
|
||||
// 32-bit hook host through WINE_ACCESS_EXCLUDE_HOOK_PROGRAMS (newline-joined),
|
||||
// an internal channel the reader never sets. The bounds mirror the
|
||||
// readers' own validation so either side rejects the same names.
|
||||
// readers' own validation so either side rejects the same names. Newlines
|
||||
// are rejected in names, so semicolons in executable names remain intact.
|
||||
#define WINE_ACCESS_MAX_HOOK_EXCLUSIONS 256
|
||||
#define WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH 255
|
||||
|
||||
@@ -56,7 +57,7 @@ static inline int wine_access_hook_exclusions_parse(WineAccessHookExclusions *li
|
||||
const WCHAR *start = value;
|
||||
for (;;) {
|
||||
const WCHAR *end = start;
|
||||
while (*end && *end != L';') ++end;
|
||||
while (*end && *end != L'\n') ++end;
|
||||
const int length = (int)(end - start);
|
||||
if (length && length <= WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH) {
|
||||
WCHAR name[WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH + 1];
|
||||
|
||||
@@ -1171,6 +1171,7 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, char *, int) {
|
||||
WINE_ACCESS_VERSION, WINE_ACCESS_REVISION, WINE_ACCESS_MODIFIED);
|
||||
bool validReader = true;
|
||||
bool validEndpoint = true;
|
||||
bool validHookExclusions = true;
|
||||
std::string readerPath, readerInterface;
|
||||
bool dialogReaderEnabled = true, controllerEnabled = true;
|
||||
for (int index = 1; index < argumentCount; ++index) {
|
||||
@@ -1180,8 +1181,10 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, char *, int) {
|
||||
}
|
||||
if (lstrcmpW(arguments[index], L"--exclude-hook-program") == 0) {
|
||||
if (++index == argumentCount ||
|
||||
!wine_access_hook_exclusions_add(&hookExclusions, arguments[index]))
|
||||
std::fprintf(stderr, "wine-access: ignoring invalid --exclude-hook-program value\n");
|
||||
!wine_access_hook_exclusions_add(&hookExclusions, arguments[index])) {
|
||||
validHookExclusions = false;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (lstrcmpW(arguments[index], L"--no-controller") == 0) {
|
||||
@@ -1211,6 +1214,11 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, char *, int) {
|
||||
else { validReader = false; break; }
|
||||
}
|
||||
LocalFree(arguments);
|
||||
if (!validHookExclusions) {
|
||||
std::fprintf(stderr, "wine-access: --exclude-hook-program requires a valid executable basename "
|
||||
"and at most %d unique exclusions\n", WINE_ACCESS_MAX_HOOK_EXCLUSIONS);
|
||||
return 1;
|
||||
}
|
||||
if (!validReader) {
|
||||
std::fprintf(stderr, "wine-access: --reader requires cthulhu or orca\n");
|
||||
return 1;
|
||||
@@ -1235,7 +1243,7 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, char *, int) {
|
||||
std::vector<WCHAR> joined(joinedLength);
|
||||
joined[0] = 0;
|
||||
for (int index = 0; index < hookExclusions.count; ++index) {
|
||||
if (index) lstrcatW(joined.data(), L";");
|
||||
if (index) lstrcatW(joined.data(), L"\n");
|
||||
lstrcatW(joined.data(), hookExclusions.names[index]);
|
||||
}
|
||||
if (joined.size() >= 32767 ||
|
||||
|
||||
+7
-1
@@ -853,9 +853,15 @@ xvfb-run -a python3 tests/menu_integration.py --build-dir build --fixture hooks
|
||||
|
||||
These start a full helper before an excluded executable, exercise foreground
|
||||
switches, and assert that neither native hook DLL is loaded into that process.
|
||||
The executable name contains a space and differs in case from the exclusion.
|
||||
The executable name contains a space and a semicolon, differs in case from
|
||||
the exclusion, and appears between other entries to check the 32-bit handoff.
|
||||
Run the same checks without `--exclude-hooks` to verify normal attachment.
|
||||
|
||||
Run `xvfb-run -a python3 tests/diagnostics_test.py --build-dir build` to check
|
||||
that missing, malformed, oversized and overflowing exclusions fail startup
|
||||
before hooks start, even with a compatible reader available. Valid duplicate
|
||||
entries still collapse to one exclusion in the ready record.
|
||||
|
||||
For live acceptance, configure an exclusion before starting helpers, launch a
|
||||
game through its launcher, and verify that its process never loads either
|
||||
Wine Access hook DLL while NVDA/Tolk announcements continue. Check both
|
||||
|
||||
@@ -113,16 +113,14 @@ with wine_test_directory(prefix="wine-access-diagnostics-") as temporary:
|
||||
helper.terminate()
|
||||
helper.wait(timeout=5)
|
||||
helper = None
|
||||
# Exclusion flags are counted in the ready record: duplicates
|
||||
# collapse, invalid values are rejected and reported.
|
||||
# Valid exclusion flags are counted once in the ready record.
|
||||
logPath = testDir / "exclusions.log"
|
||||
with logPath.open("w") as diagnostics:
|
||||
helper = subprocess.Popen(
|
||||
[str(executable), "--no-controller",
|
||||
"--exclude-hook-program", "Game.exe",
|
||||
"--exclude-hook-program", "game.EXE",
|
||||
"--exclude-hook-program", "Other Program.exe",
|
||||
"--exclude-hook-program", "../bad.exe"],
|
||||
"--exclude-hook-program", "Other Program.exe"],
|
||||
env=env, stdout=subprocess.DEVNULL, stderr=diagnostics)
|
||||
deadline = time.monotonic() + 5
|
||||
while "wine-access: ready " not in logPath.read_text() and time.monotonic() < deadline:
|
||||
@@ -135,12 +133,28 @@ with wine_test_directory(prefix="wine-access-diagnostics-") as temporary:
|
||||
for line in lines if line.startswith("wine-access: ready "))
|
||||
assert ready["hook_exclusions"] == 2, ready
|
||||
assert "wine-access: hook exclusions for 2 program(s)" in lines
|
||||
assert "wine-access: ignoring invalid --exclude-hook-program value" in lines
|
||||
helper.terminate()
|
||||
helper.wait(timeout=5)
|
||||
helper = None
|
||||
# Bad exclusion configuration must fail before any hooks start, even
|
||||
# when a compatible reader is available. Never silently drop protection.
|
||||
invalidExclusions = [
|
||||
["--exclude-hook-program"],
|
||||
*[["--exclude-hook-program", name] for name in
|
||||
("", "../bad.exe", r"C:\bad.exe", " Game.exe", "Game.exe ",
|
||||
"Game\nEdition.exe", "a" * 256)],
|
||||
[argument for index in range(257)
|
||||
for argument in ("--exclude-hook-program", f"Game{index}.exe")],
|
||||
["--exclude-hook-program", "Valid.exe", "--exclude-hook-program", "../bad.exe"],
|
||||
]
|
||||
for arguments in invalidExclusions:
|
||||
failed = subprocess.run([str(executable), "--no-controller", *arguments], env=env,
|
||||
capture_output=True, text=True, timeout=5)
|
||||
assert failed.returncode == 1, failed.stderr
|
||||
assert "wine-access: --exclude-hook-program requires" in failed.stderr, failed.stderr
|
||||
assert "wine-access: ready " not in failed.stderr, failed.stderr
|
||||
finally:
|
||||
subprocess.run(["wineserver", "-k"], env=env, timeout=10, check=False)
|
||||
if helper is not None:
|
||||
helper.wait(timeout=10)
|
||||
print("PASS: version without reader/with singleton, unavailable reader, healthy and missing-hook startup, hook exclusion counts")
|
||||
print("PASS: version without reader/with singleton, unavailable reader, healthy and missing-hook startup, hook exclusion counts and rejection before startup")
|
||||
@@ -27,11 +27,12 @@ int main(void) {
|
||||
static WineAccessHookExclusions upper;
|
||||
assert(wine_access_hook_exclusions_add(&upper, name));
|
||||
assert(!wine_access_hooks_allowed(&upper, process));
|
||||
WCHAR listed[32768] = L"Other Game.exe;";
|
||||
WCHAR listed[32768] = L"Other; Game.exe\n";
|
||||
lstrcatW(listed, name);
|
||||
lstrcatW(listed, L";Third Game.exe");
|
||||
lstrcatW(listed, L"\nThird Game.exe");
|
||||
static WineAccessHookExclusions multiple;
|
||||
assert(wine_access_hook_exclusions_parse(&multiple, listed) == 3);
|
||||
assert(wine_access_hook_exclusions_match(&multiple, L"Other; Game.exe"));
|
||||
assert(!wine_access_hooks_allowed(&multiple, process));
|
||||
puts("PASS: hook exclusions check the actual process before attachment");
|
||||
return 0;
|
||||
|
||||
@@ -40,6 +40,8 @@ int main() {
|
||||
"exclusion with leading whitespace is rejected");
|
||||
ok &= check(!wine_access_hook_exclusions_add(&exclusions, L"Game.exe "),
|
||||
"exclusion with trailing whitespace is rejected");
|
||||
ok &= check(!wine_access_hook_exclusions_add(&exclusions, L"Game\nEdition.exe"),
|
||||
"exclusion containing the transport separator is rejected");
|
||||
std::vector<WCHAR> oversized(WINE_ACCESS_MAX_HOOK_EXCLUSION_LENGTH + 2, L'a');
|
||||
oversized.back() = 0;
|
||||
ok &= check(!wine_access_hook_exclusions_add(&exclusions, oversized.data()),
|
||||
@@ -52,11 +54,13 @@ int main() {
|
||||
|
||||
static WineAccessHookExclusions parsed;
|
||||
const int added = wine_access_hook_exclusions_parse(
|
||||
&parsed, L"One.exe;two.exe;C:\\bad.exe;;Two.EXE");
|
||||
&parsed, L"One.exe\ntwo;edition.exe\nC:\\bad.exe\n\nTwo;Edition.EXE");
|
||||
ok &= check(added == 2 && parsed.count == 2,
|
||||
"semicolon list keeps valid unique exclusions");
|
||||
"newline list keeps valid unique exclusions");
|
||||
ok &= check(wine_access_hook_exclusions_match(&parsed, L"ONE.EXE"),
|
||||
"parsed exclusion matches its program");
|
||||
ok &= check(wine_access_hook_exclusions_match(&parsed, L"TWO;EDITION.EXE"),
|
||||
"parsed exclusion preserves a semicolon in its program name");
|
||||
|
||||
static WineAccessHookExclusions full;
|
||||
WCHAR name[32];
|
||||
|
||||
@@ -59,7 +59,9 @@ interface = busName.rsplit(".", 1)[0] + ".WineAccess" if args.extension_endpoint
|
||||
object_path = "/" + busName.replace(".", "/") + ("/WineAccess" if args.extension_endpoint else "")
|
||||
readerArguments = ["--reader", args.reader] if args.reader else []
|
||||
if args.exclude_hooks:
|
||||
readerArguments += ["--exclude-hook-program", "EXCLUDED GAME.EXE"]
|
||||
readerArguments += ["--exclude-hook-program", "Other Game.exe",
|
||||
"--exclude-hook-program", "EXCLUDED; GAME.EXE",
|
||||
"--exclude-hook-program", "Last Game.exe"]
|
||||
if args.extension_endpoint:
|
||||
readerArguments += ["--reader-path", object_path, "--reader-interface", interface]
|
||||
xml = '<node><interface name="' + interface + '"><method name="PresentAccessibleEvent">'
|
||||
@@ -109,7 +111,7 @@ with wine_test_directory(prefix="wine-access-menus-") as temporary:
|
||||
"x" * 1100000 + "\r\n" + "x" * 1022 + "😀tail").encode("utf-8"))
|
||||
env["WINE_ACCESS_NOTEPADPP_EXE"] = "Z:" + str(appDir / args.notepadpp_exe.name).replace("/", "\\")
|
||||
env["WINE_ACCESS_SCINTILLA_DOCUMENT"] = "Z:" + str(document).replace("/", "\\")
|
||||
fixture = Path(temporary) / ("Excluded Game.exe" if args.exclude_hooks else
|
||||
fixture = Path(temporary) / ("Excluded; Game.exe" if args.exclude_hooks else
|
||||
"foobar2000.exe" if args.fixture == "foobar-controls" else "menu-fixture.exe")
|
||||
if args.exclude_hooks:
|
||||
env["WINE_ACCESS_EXPECT_NO_HOOKS"] = "1"
|
||||
|
||||
Reference in new issue
Block a user