HLE: RegOpenKeyW/RegOpenKeyExW with a null or empty subkey fail on the emulated OEM key (fix on a fork) #765

Open
opened 2026-11-26 04:13:56 +00:00 by github-bot · 4 comments
Owner

@⁠Peppacodes on GitHub · 2026-11-24 09:55 UTC · original

What's wrong

open() in crates/victory-hle/src/modules/xsystem.rs:185-187 returns ERROR_FILE_NOT_FOUND for every open below our stand-in for HKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM. That includes a null or empty subkey. Both RegOpenKeyW and RegOpenKeyExW go through it.

Microsoft's docs:

  • RegOpenKeyW, lpSubKey: if it is NULL or points to an empty string, the function returns the same handle that was passed in.
  • RegOpenKeyExW: with a NULL or empty lpSubKey on a key that isn't predefined, phkResult receives a new handle to the key.

The host does both. I checked on HKLM\Software\Microsoft\Windows NT\CurrentVersion.

The impact is low. As the code's comment says, the title opens the full path and queries ConsoleMode. This only matters for code that opens the key again this way.

Repro

After RegOpenKeyW(HKLM, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\OEM", &k) succeeds:

  • RegOpenKeyW(k, NULL, &k2) returns 2. Expected: 0, with k2 == k.
  • RegOpenKeyExW(k, L"", 0, KEY_READ, &k3) returns 2. Expected: 0.

Fix

What changed:

  • A null or empty path below our key opens the key itself. It returns the same pseudo handle, which RegCloseKey already accepts.
  • A null phkResult there gets ERROR_INVALID_PARAMETER (87), which is what the host returns.
  • Any other path below the key is still not found, since it has no subkeys.

Test

a_null_or_empty_path_opens_the_key_itself, in xsystem.rs's device_type tests:

  • It calls both functions with a null and an empty subkey, on our key and on a host key for comparison.
  • It fails on main (left: 2, right: 0) and passes with the fix.

Results on Windows 11 with Rust 1.98.1, using the CI's own commands:

  • cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • rustfmt --edition 2024 --check xsystem.rs: clean.
  • cargo xtask policy: 154 files ok.

Not changed: the path must match KEY exactly, apart from case. The host also accepts a trailing or doubled backslash.

PR creation is limited to collaborators right now, so this is an issue with the branch. I can open a PR when it reopens.

No game files used. AI use: Claude Code (Claude Opus 5.5) found this in an audit of the HLE modules, wrote the fix and the test, and ran everything above.

**@⁠Peppacodes** on GitHub · 2026-11-24 09:55 UTC · [original](https://github.com/Marvisak/VIctory/issues/765) ## What's wrong `open()` in `crates/victory-hle/src/modules/xsystem.rs:185-187` returns `ERROR_FILE_NOT_FOUND` for every open below our stand-in for `HKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM`. That includes a null or empty subkey. Both `RegOpenKeyW` and `RegOpenKeyExW` go through it. Microsoft's docs: - **`RegOpenKeyW`, `lpSubKey`:** if it is NULL or points to an empty string, the function returns the same handle that was passed in. - **`RegOpenKeyExW`:** with a NULL or empty `lpSubKey` on a key that isn't predefined, `phkResult` receives a new handle to the key. The host does both. I checked on `HKLM\Software\Microsoft\Windows NT\CurrentVersion`. The impact is low. As the code's comment says, the title opens the full path and queries `ConsoleMode`. This only matters for code that opens the key again this way. ## Repro After `RegOpenKeyW(HKLM, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\OEM", &k)` succeeds: - `RegOpenKeyW(k, NULL, &k2)` returns 2. Expected: 0, with `k2 == k`. - `RegOpenKeyExW(k, L"", 0, KEY_READ, &k3)` returns 2. Expected: 0. ## Fix - **Branch:** https://github.com/Peppacodes/VIctory/tree/fix/oem-key-empty-subkey - **Compare:** https://github.com/Marvisak/VIctory/compare/main...Peppacodes:VIctory:fix/oem-key-empty-subkey - **Commit:** `8e9f9b3`, rebased on `main` (`ffe310e`), 0 commits behind it. One file, with its test. What changed: - A null or empty path below our key opens the key itself. It returns the same pseudo handle, which `RegCloseKey` already accepts. - A null `phkResult` there gets `ERROR_INVALID_PARAMETER` (87), which is what the host returns. - Any other path below the key is still not found, since it has no subkeys. ## Test `a_null_or_empty_path_opens_the_key_itself`, in `xsystem.rs`'s `device_type` tests: - It calls both functions with a null and an empty subkey, on our key and on a host key for comparison. - It fails on `main` (`left: 2`, `right: 0`) and passes with the fix. Results on Windows 11 with Rust 1.98.1, using the CI's own commands: - `cargo test --workspace --locked`: 343 passed, 0 failed, 6 ignored. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - `rustfmt --edition 2024 --check xsystem.rs`: clean. - `cargo xtask policy`: 154 files ok. Not changed: the path must match `KEY` exactly, apart from case. The host also accepts a trailing or doubled backslash. PR creation is limited to collaborators right now, so this is an issue with the branch. I can open a PR when it reopens. No game files used. AI use: Claude Code (Claude Opus 5.5) found this in an audit of the HLE modules, wrote the fix and the test, and ran everything above.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:56 +00:00
Author
Owner

@⁠nopsled0x on GitHub · 2026-11-24 14:09 UTC · original

I checked fix/oem-key-empty-subkey (8e9f9b3, on top of ffe310e) on Windows 10, debug build:

  • cargo test -p victory-hle --locked -- xsystem: 5 passed, 0 failed, including device_type::tests::a_null_or_empty_path_opens_the_key_itself.
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean.
  • From reading the diff (not tested beyond the unit test above): a null or empty subkey under the OEM key now returns the key itself, and a null phkResult there gets ERROR_INVALID_PARAMETER. is(sub, "") is never reached with a null pointer, because sub.is_null() short-circuits first. I found no new panic path inside the extern "system" functions, and RegCloseKey accepts the pseudo handle without calling the host.
  • Observation, not part of this diff: with a non-empty subkey and a null phkResult, the code returns ERROR_FILE_NOT_FOUND before looking at the output pointer. I believe the host checks the pointer first, but I did not verify that.

Not verified: cargo test --workspace, --features diagnostics, cargo xtask policy, rustfmt, workspace-wide clippy, whether these tests compile on non-Windows targets, or in-game behavior.

AI-assisted verification (Claude); tests were run locally by me.

**@⁠nopsled0x** on GitHub · 2026-11-24 14:09 UTC · [original](https://github.com/Marvisak/VIctory/issues/765#issuecomment-7133927206) I checked `fix/oem-key-empty-subkey` (8e9f9b3, on top of ffe310e) on Windows 10, debug build: - `cargo test -p victory-hle --locked -- xsystem`: 5 passed, 0 failed, including `device_type::tests::a_null_or_empty_path_opens_the_key_itself`. - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`: clean. - From reading the diff (not tested beyond the unit test above): a null or empty subkey under the OEM key now returns the key itself, and a null `phkResult` there gets `ERROR_INVALID_PARAMETER`. `is(sub, "")` is never reached with a null pointer, because `sub.is_null()` short-circuits first. I found no new panic path inside the `extern "system"` functions, and `RegCloseKey` accepts the pseudo handle without calling the host. - Observation, not part of this diff: with a non-empty subkey and a null `phkResult`, the code returns `ERROR_FILE_NOT_FOUND` before looking at the output pointer. I believe the host checks the pointer first, but I did not verify that. Not verified: `cargo test --workspace`, `--features diagnostics`, `cargo xtask policy`, `rustfmt`, workspace-wide clippy, whether these tests compile on non-Windows targets, or in-game behavior. _AI-assisted verification (Claude); tests were run locally by me._
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 19:42 UTC · original

@⁠Peppacodes your fix for this issue is now in a pull request, #1603, together with the three others of yours (#762, #764, #765, #832): the branches are merged as they are, with your commits and your name unchanged, onto main ffe310e. Clippy (both runs) and cargo test --workspace pass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1603. AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-24 19:42 UTC · [original](https://github.com/Marvisak/VIctory/issues/765#issuecomment-7142473858) @⁠Peppacodes your fix for this issue is now in a pull request, #1603, together with the three others of yours (#762, #764, #765, #832): the branches are merged as they are, with your commits and your name unchanged, onto `main` `ffe310e`. Clippy (both runs) and `cargo test --workspace` pass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1603. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:51 UTC · original · edited 2026-11-25 09:54 UTC

Automated triage for the maintainers.

Still confirmed on current main (940d32f): open in crates/victory-hle/src/modules/xsystem.rs returns ERROR_FILE_NOT_FOUND for every open whose root is the emulated OEM key, including a null or empty subkey. Both RegOpenKeyW and RegOpenKeyExW go through it. The impact is low, as the report says, because the title opens the full path.

No open pull request carries this change now. #1431 was closed without being merged, and the bundle #1603 is not open. Pull requests are open to everyone, so please open one from fix/oem-key-empty-subkey (8e9f9b3), rebased on current main. It already has a regression test, a_null_or_empty_path_opens_the_key_itself. The point raised above, that a null phkResult with a non-empty subkey returns ERROR_FILE_NOT_FOUND before the pointer is checked, can be settled in that pull request.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:51 UTC · [original](https://github.com/Marvisak/VIctory/issues/765#issuecomment-7152301072) · edited 2026-11-25 09:54 UTC <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-25T07:26:45Z at=2026-11-25T09:50:38Z --> Automated triage for the maintainers. Still confirmed on current `main` (`940d32f`): `open` in `crates/victory-hle/src/modules/xsystem.rs` returns `ERROR_FILE_NOT_FOUND` for every open whose root is the emulated OEM key, including a null or empty subkey. Both `RegOpenKeyW` and `RegOpenKeyExW` go through it. The impact is low, as the report says, because the title opens the full path. No open pull request carries this change now. #1431 was closed without being merged, and the bundle #1603 is not open. Pull requests are open to everyone, so please open one from `fix/oem-key-empty-subkey` (`8e9f9b3`), rebased on current `main`. It already has a regression test, `a_null_or_empty_path_opens_the_key_itself`. The point raised above, that a null `phkResult` with a non-empty subkey returns `ERROR_FILE_NOT_FOUND` before the pointer is checked, can be settled in that pull request. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 07:26 UTC · original

Following up on the request to compare with #1431: its author closed it without merging after the triage comment here. The Windows regression test passed. The outstanding evidence is a caller reopening an already-open OEM key with a null or empty subkey. An initial open of the full key path would exercise a different operation.

AI-assisted follow-up based on the public review history.

**@⁠Dathinel** on GitHub · 2026-11-25 07:26 UTC · [original](https://github.com/Marvisak/VIctory/issues/765#issuecomment-7155867674) Following up on the request to compare with #1431: its author [closed it without merging](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1431) after the triage comment here. The Windows regression test passed. The outstanding evidence is a caller reopening an already-open OEM key with a null or empty subkey. An initial open of the full key path would exercise a different operation. AI-assisted follow-up based on the public review history.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#765
No description provided.