upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/vk_queue_query_sync_test.cpp
diff options
context:
space:
mode:
authorcixotdev <339371196+cixotdev@users.noreply.github.com>2026-11-22 22:22:27 -0300
committercixotdev <339371196+cixotdev@users.noreply.github.com>2026-11-22 22:34:11 -0300
commit111eb7e6f67a0bdc26bdabf0de269cf6809558a7 (patch)
tree24b28dad008fae22c29e9ae7dd3b8d7f97cbe0af /runtime/test/vk_queue_query_sync_test.cpp
parent03b09a086592a197db64d91655c6e65c30764d96 (diff)
winhttp_offline: initialize server/port and hold ref across HANDLE_CREATED
In `open_connection()` (`WinHttpConnect`), `make_handle(Kind::Connect, s, s->async)` previously inserted the new `Handle` into `live()` and synchronously invoked `WINHTTP_CALLBACK_STATUS_HANDLE_CREATED` before `c->server = server` and `c->port = port` were assigned, and without holding a temporary reference on the handle while `HANDLE_CREATED` ran. This caused three issues when a `HANDLE_CREATED` callback acted on the handle inline or handed it to another thread: 1. Calling `WinHttpCloseHandle(self)` inside `HANDLE_CREATED` erased and freed `Handle` (`refs` 1 -> 0 -> `delete h`) before `make_handle()` returned, causing `open_connection()` to write `server` and `port` into freed heap memory (use-after-free). 2. Because `make_handle()` held no reference across `HANDLE_CREATED`, `WinHttpCloseHandle(self)` inside `HANDLE_CREATED` fired `WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING` re-entrantly before `HANDLE_CREATED` returned and still returned the freed non-null `HINTERNET` handle from `WinHttpConnect` / `WinHttpOpenRequest`, whereas native `winhttp.dll` (measured on Windows 11 26200) fires `HANDLE_CLOSING` after `HANDLE_CREATED` exits and returns `NULL` with `ERROR_WINHTTP_OPERATION_CANCELLED` (12017). 3. Opening and sending a request from inside `HANDLE_CREATED` (or from a worker thread notified by it) caused `log_refused()` / `server_of()` to read an empty `server` and port `0` (`:0`) or race with `std::wstring` assignment. Initialize `h->server` and `h->port` inside `make_handle()` before inserting into `live()`, hold an extra reference across `WINHTTP_CALLBACK_STATUS_HANDLE_CREATED` so `HANDLE_CLOSING` fires after `HANDLE_CREATED` returns, and return `nullptr` with `ERROR_WINHTTP_OPERATION_CANCELLED` if the callback closed the handle. Verification (synthetic tests only, no game files): - `winhttp_offline_test`: 57/57 checks pass via CTest and direct run - MSVC `/fsanitize=address`: 57/57 checks pass with 0 ASan errors (reproduced `heap-use-after-free` on unpatched `origin/main`) - Adjacent non-GPU runtime shim tests (`loader`, `dll_thread_calls`, `unimplemented_policy`, `xmem`, `process_cmdline`, `file_system`, `winhttp_offline`, `xgameruntime`): 8/8 passed via CTest - `python -I scripts/check_no_game_data.py`: passed Coordination claim: https://github.com/ItsNotRexed/Leonida/issues/4257#issuecomment-7088991989 AI-assisted implementation and testing.
Diffstat (limited to 'runtime/test/vk_queue_query_sync_test.cpp')
0 files changed, 0 insertions, 0 deletions