HLE: guard against null GWLP_USERDATA in XGameUi dialog WM_COMMAND handler #1373

Closed
github-bot wants to merge 1 commit from gh-pr/1373/head into gh-pr/1373/base
Owner

@⁠mgunes1311-lab on GitHub · 2026-11-24 17:39 UTC · original
mgunes1311-lab:hle-xgameui-null-userdata → main · +54 −11 · 1 files · 1 commits · closed without merging

In crates/victory-hle/src/modules/xgameui.rs, dialog::procedure previously formed &mut *(wm::GetWindowLongPtrW(dialog, wm::GWLP_USERDATA) as *mut Entry) unconditionally in the WM_COMMAND handler. If WM_COMMAND arrives before WM_INITDIALOG initializes GWLP_USERDATA, forming &mut Entry from null is immediate UB and crashes on IDOK.

Changes

  • Check (wm::GetWindowLongPtrW(dialog, wm::GWLP_USERDATA) as *mut Entry).as_mut() in dialog::procedure and return 0 when user data is null.
  • Made dialog::procedure pub(super) for direct unit testing and added dialog_wm_command_ignores_missing_user_data.

Verification

  • cargo test -p victory-hle --target x86_64-pc-windows-msvc --locked xgameui:: (2 passed; 0 failed)
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --target x86_64-pc-windows-msvc --locked
  • cargo run -p xtask --target x86_64-pc-windows-msvc --locked -- policy --staged (asset policy: 1 files ok)
**@⁠mgunes1311-lab** on GitHub · 2026-11-24 17:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/1373) `mgunes1311-lab:hle-xgameui-null-userdata` → `main` · +54 −11 · 1 files · 1 commits · closed without merging In `crates/victory-hle/src/modules/xgameui.rs`, `dialog::procedure` previously formed `&mut *(wm::GetWindowLongPtrW(dialog, wm::GWLP_USERDATA) as *mut Entry)` unconditionally in the `WM_COMMAND` handler. If `WM_COMMAND` arrives before `WM_INITDIALOG` initializes `GWLP_USERDATA`, forming `&mut Entry` from null is immediate UB and crashes on `IDOK`. ### Changes - Check `(wm::GetWindowLongPtrW(dialog, wm::GWLP_USERDATA) as *mut Entry).as_mut()` in `dialog::procedure` and return `0` when user data is null. - Made `dialog::procedure` `pub(super)` for direct unit testing and added `dialog_wm_command_ignores_missing_user_data`. ### Verification - `cargo test -p victory-hle --target x86_64-pc-windows-msvc --locked xgameui::` (`2 passed; 0 failed`) - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` - `RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --target x86_64-pc-windows-msvc --locked` - `cargo run -p xtask --target x86_64-pc-windows-msvc --locked -- policy --staged` (`asset policy: 1 files ok`)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:29:17 +00:00
github-bot closed this pull request 2026-11-26 04:29:17 +00:00
Author
Owner

@⁠acetonahard-code on GitHub · 2026-11-24 21:03 UTC · original

Tested on Windows 11 with the repo toolchain, merged into current main (ffe310e):

cargo test -p victory-hle passed failed ignored
main 95 0 0
main + this PR 96 0 0
  • The new test passes.
  • cargo clippy --all-targets -- -D warnings, with and without --all-features: clean.

I didn't test with game data.


Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.

**@⁠acetonahard-code** on GitHub · 2026-11-24 21:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/1373#issuecomment-7144427706) Tested on Windows 11 with the repo toolchain, merged into current `main` (ffe310e): | `cargo test -p victory-hle` | passed | failed | ignored | |---|---|---|---| | `main` | 95 | 0 | 0 | | `main` + this PR | 96 | 0 | 0 | - The new test passes. - `cargo clippy --all-targets -- -D warnings`, with and without `--all-features`: clean. I didn't test with game data. --- <sub>Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.</sub>
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:38 UTC · original

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1515. Same null user-data guard as #1515, wrapped in reformatting of unrelated lines and a visibility change.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/1373#issuecomment-7148731883) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1515. Same null user-data guard as #1515, wrapped in reformatting of unrelated lines and a visibility change. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!1373
No description provided.