Skip to content

winhttp_offline: an empty server name and a context option of the wrong size fail as on the host (WINHTTP-ARG-CHECKS) - #2383

Draft
syfyra wants to merge 1 commit into
ProjectLeonida:mainfrom
syfyra:fix/winhttp-arg-checks
Draft

syfyra wants to merge 1 commit into
ProjectLeonida:mainfrom
syfyra:fix/winhttp-arg-checks

Conversation

@syfyra

@syfyra syfyra commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: WINHTTP-ARG-CHECKS

What and why

I compared the offline WinHTTP shim with the host's winhttp.dll on the calls that need no network: handles, options, timeouts and the argument checks. A small ctypes probe ran on Windows 11 against .invalid names, with no request sent. Two answers differ:

call host winhttp.dll shim on main
WinHttpConnect(session, L"", 80, 0) ERROR_WINHTTP_INVALID_URL (12005) ERROR_INVALID_PARAMETER (87)
WinHttpConnect(session, nullptr, 80, 0) ERROR_INVALID_PARAMETER ERROR_INVALID_PARAMETER
WinHttpSetOption(h, WINHTTP_OPTION_CONTEXT_VALUE, buf, 4) ERROR_INSUFFICIENT_BUFFER ERROR_INSUFFICIENT_BUFFER
WinHttpSetOption(h, WINHTTP_OPTION_CONTEXT_VALUE, buf, 16) ERROR_INSUFFICIENT_BUFFER succeeds and takes the first 8 bytes

Everything else in the probe already matched:

  • the context value's query and its size answer;
  • WinHttpConnect on a connect handle and WinHttpOpenRequest on a session (ERROR_WINHTTP_INCORRECT_HANDLE_TYPE);
  • a negative timeout;
  • WinHttpCloseHandle of NULL and of a closed handle;
  • the context option on a NULL handle.

Both are fixed: an empty server name now fails with ERROR_WINHTTP_INVALID_URL, and the context option takes exactly sizeof(DWORD_PTR) and leaves the handle's context as it was otherwise.

Not changed: the shim still accepts options it does not know (the host refuses an unknown option number with ERROR_WINHTTP_INVALID_OPTION). The file's header says options are accepted on purpose, and matching the host there would need the host's list of options per handle type.

Tested

Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:

Not tested under Wine.

GPUs tested: n/a (CPU tests)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

…ng size fail as on the host (WINHTTP-ARG-CHECKS)

Two argument checks answered differently from the host's winhttp.dll
(measured on Windows 11):
- WinHttpConnect with an empty server name failed with
  ERROR_INVALID_PARAMETER; the host gives ERROR_WINHTTP_INVALID_URL (a
  null name stays ERROR_INVALID_PARAMETER on both).
- WinHttpSetOption(WINHTTP_OPTION_CONTEXT_VALUE) accepted any length of
  at least a DWORD_PTR and read the first eight bytes; the host takes
  exactly a DWORD_PTR and refuses 16 bytes with ERROR_INSUFFICIENT_BUFFER
  as it does 4, keeping the context it had.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fiestorra

Copy link
Copy Markdown
Contributor

Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites on two assertions.

1. It applies. merge-tree clean; the commits cherry-pick onto main 012b79a67 without a conflict. Two files: runtime/shims/winhttp_offline.cpp and runtime/test/winhttp_offline_test.cpp.

2. With the branch its test passes:

ctest -R 'winhttp_offline'
100% tests passed, 0 tests failed out of 1

3. The control - revert only the shim, keep the test:

git checkout origin/main -- runtime/shims/winhttp_offline.cpp
cmake --build … --target winhttp_offline_test
ctest -R 'winhttp_offline' --output-on-failure
0% tests passed, 1 tests failed out of 1
FAIL a 16-byte WINHTTP_OPTION_CONTEXT_VALUE fails with ERROR_INSUFFICIENT_BUFFER too, as on the host
FAIL and the context set before stays

Both failures name the rule the change adds: querying WINHTTP_OPTION_CONTEXT_VALUE with a 16-byte buffer must fail with ERROR_INSUFFICIENT_BUFFER on the 64-bit path as well, and the context set before must survive the failed query. That second assertion is the one worth noting - the change is not only about the error code, it is about not losing state when the query is refused.

What I did not test: the rest of the offline WinHTTP surface, and whether the host (a real winhttp.dll) behaves the same way on the 32-bit path.

Why I am commenting: I verify open pull requests that replay onto current main, then revert only the source change and re-run. 22 controls so far: 15 bite.

Written with an AI assistant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants