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

Closed
mgunes1311-lab wants to merge 1 commit from upstream-pr/1373 into main
mgunes1311-lab commented 2026-11-24 17:39:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mgunes1311-lab on 2026-11-24T17:39:12Z.


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)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587802419 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1373). Originally posted by [mgunes1311-lab](https://github.com/mgunes1311-lab) on 2026-11-24T17:39:12Z. --- 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`)
BaggyALPHA commented 2026-11-24 18:05:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BaggyALPHA on 2026-11-24T17:41:17Z.

Review: COMMENTED


I reproduced this independently on Windows using a real hidden Win32 window whose user data was still zero. Calling the dialog procedure with an OK command aborted on a null dereference on upstream main. With this PR applied, the same hidden-window test returned unhandled for OK, Cancel and an edit-control command. The HLE suite passed 97 tests including that temporary probe. No visible dialog or game files were needed.

AI-assisted (Codex).

<!-- greyfinch-sync:Marvisak/VIctory:review:6044368988 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1373#pullrequestreview-6044368988). Originally posted by [BaggyALPHA](https://github.com/BaggyALPHA) on 2026-11-24T17:41:17Z. **Review:** COMMENTED --- I reproduced this independently on Windows using a real hidden Win32 window whose user data was still zero. Calling the dialog procedure with an OK command aborted on a null dereference on upstream main. With this PR applied, the same hidden-window test returned unhandled for OK, Cancel and an edit-control command. The HLE suite passed 97 tests including that temporary probe. No visible dialog or game files were needed. AI-assisted (Codex).
acetonahard-code commented 2026-11-24 21:28:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by acetonahard-code on 2026-11-24T21:03:55Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144427706 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1373#issuecomment-7144427706). Originally posted by [acetonahard-code](https://github.com/acetonahard-code) on 2026-11-24T21:03:55Z. --- 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>
upstream-sync closed this pull request 2026-11-25 01:06:23 +00:00
Marvisak commented 2026-11-25 01:08:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:38:57Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148731883 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1373#issuecomment-7148731883). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:38:57Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1373
No description provided.