HLE/net: a blocked name lookup clears the caller's result slot #1448

Closed
CwWwWwW wants to merge 1 commit from upstream-pr/1448 into main
CwWwWwW commented 2026-11-27 09:07:18 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T09:07:18Z.


Problem

This layer answers forward name lookups offline: a name that is not localhost or an IP literal fails with WSAHOST_NOT_FOUND without asking the host. The four wrappers that carry a result-list out-parameter did that with a bare return WSAHOST_NOT_FOUND; before writing the caller's slot:

  • getaddrinfo (net.rs:540)
  • GetAddrInfoW (net.rs:554)
  • GetAddrInfoExA (net.rs:568)
  • GetAddrInfoExW (net.rs:588)

Windows' own failed lookup does set the slot to null - verified offline with a standalone probe (no game): with the slot poisoned to 0x1234, getaddrinfo returning 11001 (WSAHOST_NOT_FOUND) and returning 10044 (bad hints) both leave *result == NULL. So a title that treats the slot as "free or reuse it on the error path" (e.g. freeaddrinfo() in a cleanup label, or reusing the variable for the next lookup) finds a wild pointer - an access violation that kills the emulator - or a stale list pointer, a double free. It also diverges from the host/console behaviour on a path every title hits on its first attempt to reach a server.

Fix

A small helper clears the slot when non-null and returns WSAHOST_NOT_FOUND; the four blocked returns use it. getnameinfo/GetNameInfoW have no list out-parameter and are unchanged, as is gethostbyname, which returns its pointer directly. One file changed (crates/victory-hle/src/modules/net.rs, +83/-4 including the test).

Regression test

net::tests::blocked_lookups_clear_the_result_slot poisons the slot with a sentinel and calls all four wrappers with a blocked name: on the old code it fails at the first assertion (getaddrinfo left the caller's slot); with the change all four null it, and a null slot is tolerated.

Verification

  • cargo test -p victory-hle --lib --locked: 104 passed, 0 failed
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean
  • git diff --check: clean; one file changed

Found by this mission's read-only audit of the net module (its other categories - threads, socket/handle lifetime, buffer ownership, locks - came out clean); independently implemented for this tree, no external code used.

The PR's Clippy check fails on main already: at 9a9091d cargo clippy --workspace --all-targets fails in victory-shader (wave64_after_loop.rs precedence; valu_tests.rs simplifiable/negated partial-ord comparisons), which open PR #1440 fixes; this diff touches only victory-hle/src/modules/net.rs, whose clippy is clean here (default and --all-features).

<!-- greyfinch-sync:fxceless/victory-fork:issue:5524032360 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1448). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-27T09:07:18Z. --- ## Problem This layer answers forward name lookups offline: a name that is not `localhost` or an IP literal fails with `WSAHOST_NOT_FOUND` without asking the host. The four wrappers that carry a result-list out-parameter did that with a bare `return WSAHOST_NOT_FOUND;` **before writing the caller's slot**: - `getaddrinfo` (net.rs:540) - `GetAddrInfoW` (net.rs:554) - `GetAddrInfoExA` (net.rs:568) - `GetAddrInfoExW` (net.rs:588) Windows' own failed lookup does set the slot to null - verified offline with a standalone probe (no game): with the slot poisoned to `0x1234`, `getaddrinfo` returning 11001 (`WSAHOST_NOT_FOUND`) and returning 10044 (bad hints) both leave `*result == NULL`. So a title that treats the slot as "free or reuse it on the error path" (e.g. `freeaddrinfo()` in a cleanup label, or reusing the variable for the next lookup) finds a wild pointer - an access violation that kills the emulator - or a stale list pointer, a double free. It also diverges from the host/console behaviour on a path every title hits on its first attempt to reach a server. ## Fix A small helper clears the slot when non-null and returns `WSAHOST_NOT_FOUND`; the four blocked returns use it. `getnameinfo`/`GetNameInfoW` have no list out-parameter and are unchanged, as is `gethostbyname`, which returns its pointer directly. One file changed (`crates/victory-hle/src/modules/net.rs`, +83/-4 including the test). ## Regression test `net::tests::blocked_lookups_clear_the_result_slot` poisons the slot with a sentinel and calls all four wrappers with a blocked name: on the old code it fails at the first assertion (`getaddrinfo left the caller's slot`); with the change all four null it, and a null slot is tolerated. ## Verification - `cargo test -p victory-hle --lib --locked`: 104 passed, 0 failed - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings`: clean - `git diff --check`: clean; one file changed Found by this mission's read-only audit of the net module (its other categories - threads, socket/handle lifetime, buffer ownership, locks - came out clean); independently implemented for this tree, no external code used. The PR's Clippy check fails on main already: at 9a9091d `cargo clippy --workspace --all-targets` fails in `victory-shader` (wave64_after_loop.rs precedence; valu_tests.rs simplifiable/negated partial-ord comparisons), which open PR #1440 fixes; this diff touches only `victory-hle/src/modules/net.rs`, whose clippy is clean here (default and --all-features).
CwWwWwW commented 2026-11-27 16:21:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T16:21:37Z.


Superseded on the VIctory-NVIDIA tree that replaced main: crates/victory-hle/src/modules/net.rs already has blocked_lookup() clearing the caller's result slot in all four wrappers, with its test. Closing.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7223166723 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1448#issuecomment-7223166723). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-27T16:21:37Z. --- Superseded on the VIctory-NVIDIA tree that replaced main: crates/victory-hle/src/modules/net.rs already has blocked_lookup() clearing the caller's result slot in all four wrappers, with its test. Closing.

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
fxceless/victory-fork!1448
No description provided.