diff --git a/CMakeLists.txt b/CMakeLists.txt index a2c457f..56610e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,7 @@ add_custom_command(OUTPUT "${browser_publisher}" ${BROWSER_PUBLISHER_LDFLAGS} DEPENDS browser_publisher.c VERBATIM) -add_custom_target(wine-access-browser-publisher ALL DEPENDS "${browser_publisher}") +add_custom_target(wine-access-browser-publisher-build ALL DEPENDS "${browser_publisher}") set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") set(generated_header "${generated_dir}/nvdaController.h") @@ -107,7 +107,7 @@ add_custom_command( add_executable(wine-access reader_events.cpp msaa_events.cpp bootstrapper_controls.cpp main.cpp browser_bridge.cpp foreground_focus.cpp list_view.cpp native_items.cpp review_capture.cpp review_x11.cpp review_service.cpp "${generated_server}") add_dependencies(wine-access wine-access-menu wine-access-menu32 wine-access-version - wine-access-browser-worker wine-access-browser-publisher) + wine-access-browser-worker wine-access-browser-publisher-build) target_compile_features(wine-access PRIVATE cxx_std_20) target_include_directories(wine-access PRIVATE "${generated_dir}") target_link_libraries(wine-access PRIVATE @@ -199,6 +199,24 @@ if(BUILD_TESTING) add_test(NAME browser-publisher-snapshot COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tests/browser/publisher_snapshot_test.sh" "${browser_publisher}") set_tests_properties(browser-publisher-snapshot PROPERTIES TIMEOUT 240 RUN_SERIAL TRUE) + set(publisher_lifetime_test "${CMAKE_CURRENT_BINARY_DIR}/browser-publisher-lifetime-test") + add_custom_command(OUTPUT "${publisher_lifetime_test}" + COMMAND "${HOST_C_COMPILER}" -std=c11 -g -Wall -Wextra ${BROWSER_PUBLISHER_CFLAGS} + -o "${publisher_lifetime_test}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/browser/publisher_lifetime_test.c" + ${BROWSER_PUBLISHER_LDFLAGS} + DEPENDS tests/browser/publisher_lifetime_test.c browser_publisher.c VERBATIM) + add_custom_target(browser-publisher-lifetime-test-build ALL DEPENDS "${publisher_lifetime_test}") + add_test(NAME browser-publisher-lifetime COMMAND "${publisher_lifetime_test}") + set(worker_privacy_test "${CMAKE_CURRENT_BINARY_DIR}/browser-worker-privacy-test.exe") + add_custom_command(OUTPUT "${worker_privacy_test}" + COMMAND "${MINGW_CXX_COMPILER}" -std=c++20 -g -Wall -Wextra -static + -I "${ia2_generated_dir}" -o "${worker_privacy_test}" + "${CMAKE_CURRENT_SOURCE_DIR}/tests/browser/worker_privacy_test.cpp" ${ia2_guids} + -loleacc -lole32 -loleaut32 -luuid + DEPENDS tests/browser/worker_privacy_test.cpp browser_worker.cpp ${ia2_headers} ${ia2_guids} VERBATIM) + add_custom_target(browser-worker-privacy-test-build ALL DEPENDS "${worker_privacy_test}") + add_dependencies(browser-worker-privacy-test-build wine-access-browser-worker) + add_wine_test(browser-worker-privacy 35 "${worker_privacy_test}") endif() # Winegcc emits a launcher and a Winelib sidecar. CMake's normal target diff --git a/README.md b/README.md index 336082b..219e4dd 100644 --- a/README.md +++ b/README.md @@ -212,10 +212,11 @@ connection therefore do not establish that the standalone menu and editor support is installed. Missing MUSHclient menu or command-field feedback can be caused by this installation mismatch. -From this standalone repository, rebuild and install the complete five-file +From this standalone repository, rebuild and install the complete seven-file helper set using `./build.sh`, then reload Cthulhu from its original desktop session. Keep the launcher, sidecar, both hook DLLs, and 32-bit host from the same -build together. Updating only the reader executable does not update this helper. +build together, including the browser worker and publisher. Updating only the +reader executable does not update this helper. For diagnosis, verify the running helper's executable path and session bus, compare installed files with the standalone build, and check that @@ -605,7 +606,7 @@ Scintilla reads at most 4096 encoded bytes per report, then limits output to 1023 UTF-16 units without splitting surrogate pairs. Wrapped Scintilla lines report the underlying document line. -Keep all five installed files together. Native menus and standard Edit controls +Keep all seven installed files together. Native menus and standard Edit controls are supported in 32-bit and 64-bit applications; custom menus that do not send `WM_MENUSELECT` are not covered. diff --git a/browser_publisher.c b/browser_publisher.c index 24adac3..40bb4f4 100644 --- a/browser_publisher.c +++ b/browser_publisher.c @@ -411,7 +411,9 @@ static WaNode *load_node(JsonObject *object, WaNode *parent) { node->parent = parent; WaNode *previous = node_for_id(node->id); if (previous && !previous->defunct) g_warning("duplicate uniqueID %ld", node->id); - g_hash_table_insert(nodesById, &node->id, node); + // The key lives inside the node. Replacing just the value would retain + // the old node's key after that node is retired and freed. + g_hash_table_replace(nodesById, &node->id, node); node->children = g_ptr_array_new(); JsonArray *children = json_object_get_array_member(object, "children"); @@ -1854,13 +1856,14 @@ static void defunct_subtree(WaNode *node) { if (node->defunct) return; if (traceMessages) g_printerr("trace: defunct %ld %s\n", node->id, atk_role_get_name(node->atkRole)); node->defunct = TRUE; + node->parent = NULL; + atk_object_set_parent(node->accessible, NULL); if (node->id == focusedId) focusedId = 0; if (node_for_id(node->id) == node) g_hash_table_remove(nodesById, &node->id); atk_object_notify_state_change(node->accessible, ATK_STATE_DEFUNCT, TRUE); for (guint i = 0; i < node->children->len; i++) { WaNode *child = g_ptr_array_index(node->children, i); defunct_subtree(child); - child->parent = NULL; } g_ptr_array_set_size(node->children, 0); g_clear_object(&node->hyperlink); diff --git a/browser_worker.cpp b/browser_worker.cpp index 7537e66..847c453 100644 --- a/browser_worker.cpp +++ b/browser_worker.cpp @@ -238,8 +238,9 @@ IAccessible *resolve(long id) { long msaa_state(IAccessible *accessible) { VARIANT value; VariantInit(&value); - long state = 0; - if (SUCCEEDED(accessible->get_accState(selfChild, &value)) && value.vt == VT_I4) state = value.lVal; + // Unknown protection must never authorize value, text or boundary reads. + long state = STATE_SYSTEM_PROTECTED; + if (accessible->get_accState(selfChild, &value) == S_OK && value.vt == VT_I4) state = value.lVal; VariantClear(&value); return state; } @@ -1142,6 +1143,7 @@ bool activate_web_content() { int wmain(int argc, wchar_t **argv) { QueryPerformanceFrequency(&perfFrequency); + InitializeCriticalSection(&outputLock); std::wstring titlePart; HWND hwndArgument = nullptr; double waitWindowSeconds = 30; @@ -1161,7 +1163,6 @@ int wmain(int argc, wchar_t **argv) { return 2; } - InitializeCriticalSection(&outputLock); mainThreadId = GetCurrentThreadId(); MSG message; PeekMessageW(&message, nullptr, WM_USER, WM_USER, PM_NOREMOVE); // create the queue before the input thread posts diff --git a/build.sh b/build.sh index 8708915..eda3dfc 100755 --- a/build.sh +++ b/build.sh @@ -34,7 +34,8 @@ fi prefix=${2:-"$defaultPrefix"} installDir="${prefix%/}/libexec/wine-access" installedFiles=(wine-access.exe wine-access.exe.so wine-access-menu.dll - wine-access-menu32.dll wine-access-menu-host32.exe) + wine-access-menu32.dll wine-access-menu-host32.exe + wine-access-browser-worker.exe wine-access-browser-publisher) orcaSourceDir="$projectDir/orca/wine_access" orcaInstallDir="${prefix%/}/share/wine-access/orca/wine_access" systemOrcaInstallDir="$systemPrefix/share/wine-access/orca/wine_access" diff --git a/docs/browser.md b/docs/browser.md index 1b90610..6624813 100644 --- a/docs/browser.md +++ b/docs/browser.md @@ -89,6 +89,10 @@ Rules established by comparison with native Chromium 158 and Electron 42: ## Verification +- `ctest -R 'browser-publisher-lifetime|browser-worker-privacy'`: checks node + retirement, replacement ID ownership, retained defunct objects, failed or + malformed password-state queries, and worker argument-error logging. + Unknown protection is treated as protected before reading values or text. - `ctest -R browser-publisher-snapshot`: publishes a recorded Electron 45 snapshot (no Wine) and compares the tree, including text boundaries, with native Chromium 158 and Electron 42. diff --git a/tests/browser/publisher_lifetime_test.c b/tests/browser/publisher_lifetime_test.c new file mode 100644 index 0000000..8375350 --- /dev/null +++ b/tests/browser/publisher_lifetime_test.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// Exercise retirement without atk-bridge retaining references to the objects. +#define main publisher_main +#include "../../browser_publisher.c" +#undef main + +int main(void) { + JsonObject *tree = parse_line("{\"id\":1,\"msaaRole\":9,\"children\":[" + "{\"id\":2,\"msaaRole\":42,\"children\":[" + "{\"id\":3,\"msaaRole\":42,\"children\":[]}]}]}"); + build_initial_tree(tree, 0); + // Reusing an ID must not leave the hash key owned by the retired object. + WaNode *old = node_for_id(2); + JsonObject *replacement = parse_line("{\"id\":2,\"msaaRole\":43,\"children\":[]}"); + g_test_expect_message(NULL, G_LOG_LEVEL_WARNING, "*duplicate uniqueID 2*"); + WaNode *fresh = load_node(replacement, frameNode); + g_test_assert_expected_messages(); + gpointer storedKey = NULL; + g_assert_true(g_hash_table_lookup_extended(nodesById, &fresh->id, &storedKey, NULL)); + g_assert_true(storedKey == &fresh->id); + create_accessibles(fresh); + g_ptr_array_index(frameNode->children, 0) = fresh; + defunct_subtree(old); + g_assert_true(node_for_id(2) == fresh); + g_assert_null(node_for_id(3)); + AtkObject *retained = g_object_ref(fresh->accessible); + defunct_subtree(applicationNode); + g_assert_cmpint(atk_object_get_index_in_parent(retained), ==, -1); + g_assert_null(atk_object_get_parent(retained)); + g_object_unref(retained); + g_assert_cmpuint(g_hash_table_size(nodesById), ==, 0); + g_hash_table_unref(nodesById); + json_object_unref(tree); + json_object_unref(replacement); + return 0; +} diff --git a/tests/browser/worker_privacy_test.cpp b/tests/browser/worker_privacy_test.cpp new file mode 100644 index 0000000..08894fb --- /dev/null +++ b/tests/browser/worker_privacy_test.cpp @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +#define wmain browser_worker_main +#include "../../browser_worker.cpp" +#undef wmain +#include + +class StateProvider : public IAccessible { + public: + HRESULT result = S_OK; + VARTYPE type = VT_I4; + LONG state = 0; + int valueCalls = 0; + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void **out) override { *out = nullptr; return E_NOINTERFACE; } + ULONG STDMETHODCALLTYPE AddRef() override { return 1; } + ULONG STDMETHODCALLTYPE Release() override { return 1; } + HRESULT STDMETHODCALLTYPE get_accState(VARIANT, VARIANT *out) override { + out->vt = type; + out->lVal = state; + return result; + } + HRESULT STDMETHODCALLTYPE get_accValue(VARIANT, BSTR *out) override { + ++valueCalls; + *out = SysAllocString(L"private sentinel"); + return S_OK; + } +#define STUB(name, args) HRESULT STDMETHODCALLTYPE name args override { return E_NOTIMPL; } + STUB(GetTypeInfoCount, (UINT *)) + STUB(GetTypeInfo, (UINT, LCID, ITypeInfo **)) + STUB(GetIDsOfNames, (REFIID, LPOLESTR *, UINT, LCID, DISPID *)) + STUB(Invoke, (DISPID, REFIID, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *)) + STUB(get_accParent, (IDispatch **)) + STUB(get_accChildCount, (long *)) + STUB(get_accChild, (VARIANT, IDispatch **)) + STUB(get_accName, (VARIANT, BSTR *)) + STUB(get_accDescription, (VARIANT, BSTR *)) + STUB(get_accRole, (VARIANT, VARIANT *)) + STUB(get_accHelp, (VARIANT, BSTR *)) + STUB(get_accHelpTopic, (BSTR *, VARIANT, long *)) + STUB(get_accKeyboardShortcut, (VARIANT, BSTR *)) + STUB(get_accFocus, (VARIANT *)) + STUB(get_accSelection, (VARIANT *)) + STUB(get_accDefaultAction, (VARIANT, BSTR *)) + STUB(accSelect, (long, VARIANT)) + STUB(accLocation, (long *, long *, long *, long *, VARIANT)) + STUB(accNavigate, (long, VARIANT, VARIANT *)) + STUB(accHitTest, (long, long, VARIANT *)) + STUB(accDoDefaultAction, (VARIANT)) + STUB(put_accName, (VARIANT, BSTR)) + STUB(put_accValue, (VARIANT, BSTR)) +#undef STUB +}; + +int main() { + StateProvider provider; + for (int scenario = 0; scenario < 5; ++scenario) { + provider.result = scenario == 0 ? E_FAIL : scenario == 1 ? S_FALSE : S_OK; + provider.type = scenario == 2 ? VT_EMPTY : VT_I4; + provider.state = scenario == 3 ? STATE_SYSTEM_PROTECTED : 0; + provider.valueCalls = 0; + const bool protectedValue = scenario != 4; + assert(is_protected(&provider) == protectedValue); + std::string record; + node_record(&provider, 0, false, 0, record); + assert(provider.valueCalls == (protectedValue ? 0 : 1)); + assert((record.find("private sentinel") == std::string::npos) == protectedValue); + } + wchar_t program[] = L"worker"; + wchar_t invalid[] = L"--invalid-option"; + wchar_t *arguments[] = {program, invalid}; + assert(browser_worker_main(1, arguments) == 2); + DeleteCriticalSection(&outputLock); + assert(browser_worker_main(2, arguments) == 2); + DeleteCriticalSection(&outputLock); + return 0; +}