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

Open
github-bot wants to merge 1 commit from github-bot/gh-2383 into main AGit
Owner

@⁠syfyra on GitHub · 2026-11-26 16:43 UTC · original
syfyra:fix/winhttp-arg-checks → main · +19 −2 · 2 files · 1 commits · draft

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:

  • winhttp_offline_test gets three checks: a 16-byte context value fails with ERROR_INSUFFICIENT_BUFFER, the context set before it stays, and an empty server name fails with ERROR_WINHTTP_INVALID_URL.
    • main: 3 of 86 checks fail.
    • this branch: 86 of 86 pass.
  • No other open pull request changes these two files (scripts/pr_overlap.py from #2349).
  • scripts/check_no_game_data.py on both files.

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

**@⁠syfyra** on GitHub · 2026-11-26 16:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2383) `syfyra:fix/winhttp-arg-checks` → `main` · +19 −2 · 2 files · 1 commits · draft 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: - `winhttp_offline_test` gets three checks: a 16-byte context value fails with `ERROR_INSUFFICIENT_BUFFER`, the context set before it stays, and an empty server name fails with `ERROR_WINHTTP_INVALID_URL`. - `main`: 3 of 86 checks fail. - this branch: 86 of 86 pass. - No other open pull request changes these two files (`scripts/pr_overlap.py` from #2349). - `scripts/check_no_game_data.py` on both files. Not tested under Wine. GPUs tested: n/a (CPU tests) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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](https://claude.com/claude-code)
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 16:46:51 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2383/head:github-bot/gh-2383'
git switch 'github-bot/gh-2383'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2383'
git switch 'github-bot/gh-2383'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2383'
git switch 'github-bot/gh-2383'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2383'
git switch 'main'
git merge --squash 'github-bot/gh-2383'
git switch 'main'
git merge --ff-only 'github-bot/gh-2383'
git switch 'main'
git merge 'github-bot/gh-2383'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.