HLE: return Winsock sockaddr errors from getnameinfo on invalid input #2993

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/2995 into main
fuzeofficlal commented 2026-11-26 02:47:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:47:52Z.


Problem

name_info_flags in crates/victory-hle/src/modules/net.rs relied on socket_addr(sa, len) returning Option<SocketAddr>. When a caller passed a null sockaddr, a negative/short sa_len (< 2), a truncated AF_INET (< 16) or AF_INET6 (< 28) address, or an unsupported address family, socket_addr returned None, causing reverse_resolvable(None) to emit a spurious "network reverse lookup blocked" log and return WSAHOST_NOT_FOUND (11001) under NI_NAMEREQD.

Native Windows ws2_32.dll (getnameinfo / GetNameInfoW) instead sets and returns WSAEFAULT (10014) for null/undersized sockaddr inputs and WSAEAFNOSUPPORT (10047) for unsupported address families.

Fix

  • Add name_info_addr to parse sockaddr for getnameinfo / GetNameInfoW, returning Err(WSAEFAULT) for null or undersized buffers and Err(WSAEAFNOSUPPORT) for unsupported families.
  • Have name_info_flags return Result<i32, i32>, setting WSASetLastError(err) and returning err on invalid inputs before applying the offline reverse-lookup policy for valid IPv4/IPv6 addresses.
  • Forward the returned error directly from both getnameinfo and GetNameInfoW.

Verification

  • Added modules::net::tests::getnameinfo_reports_winsock_address_errors_instead_of_host_not_found covering both getnameinfo and GetNameInfoW across null sockaddr (NI_NAMEREQD & NI_NUMERICHOST), negative length, short header (len = 1), truncated AF_INET / AF_INET6, unsupported family (99), and valid non-loopback IPv4 (203.0.113.1 with and without NI_NAMEREQD), asserting both return values and WSAGetLastError().
  • cargo test --locked -p victory-hle -- --test-threads=1: 153/153 unit + 2/2 integration tests passed.
  • cargo clippy --locked -p victory-hle --tests -- -D warnings (default & --all-features): 0 warnings.
  • cargo xtask policy: 191 files ok.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6618401629 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2995). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T02:47:52Z. --- ## Problem `name_info_flags` in `crates/victory-hle/src/modules/net.rs` relied on `socket_addr(sa, len)` returning `Option<SocketAddr>`. When a caller passed a null `sockaddr`, a negative/short `sa_len` (`< 2`), a truncated `AF_INET` (`< 16`) or `AF_INET6` (`< 28`) address, or an unsupported address family, `socket_addr` returned `None`, causing `reverse_resolvable(None)` to emit a spurious `"network reverse lookup blocked"` log and return `WSAHOST_NOT_FOUND` (`11001`) under `NI_NAMEREQD`. Native Windows `ws2_32.dll` (`getnameinfo` / `GetNameInfoW`) instead sets and returns `WSAEFAULT` (`10014`) for null/undersized `sockaddr` inputs and `WSAEAFNOSUPPORT` (`10047`) for unsupported address families. ## Fix - Add `name_info_addr` to parse `sockaddr` for `getnameinfo` / `GetNameInfoW`, returning `Err(WSAEFAULT)` for null or undersized buffers and `Err(WSAEAFNOSUPPORT)` for unsupported families. - Have `name_info_flags` return `Result<i32, i32>`, setting `WSASetLastError(err)` and returning `err` on invalid inputs before applying the offline reverse-lookup policy for valid IPv4/IPv6 addresses. - Forward the returned error directly from both `getnameinfo` and `GetNameInfoW`. ## Verification - Added `modules::net::tests::getnameinfo_reports_winsock_address_errors_instead_of_host_not_found` covering both `getnameinfo` and `GetNameInfoW` across null `sockaddr` (`NI_NAMEREQD` & `NI_NUMERICHOST`), negative length, short header (`len = 1`), truncated `AF_INET` / `AF_INET6`, unsupported family (`99`), and valid non-loopback IPv4 (`203.0.113.1` with and without `NI_NAMEREQD`), asserting both return values and `WSAGetLastError()`. - `cargo test --locked -p victory-hle -- --test-threads=1`: **153/153 unit + 2/2 integration tests passed**. - `cargo clippy --locked -p victory-hle --tests -- -D warnings` (default & `--all-features`): 0 warnings. - `cargo xtask policy`: 191 files ok.
kotekompotek commented 2026-11-26 03:04:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:58:03Z.

Review: APPROVED


LGTM — matches real Winsock behavior. name_info_addr validates family-specific minimum lengths (16 for AF_INET, 28 for AF_INET6) and distinguishes WSAEFAULT (malformed) from WSAEAFNOSUPPORT (unknown family) — previously every bad sockaddr collapsed into WSAHOST_NOT_FOUND. WSAGetLastError is set on the failure path via wsa_error, and the offline lookup policy (numeric passthrough, loopback resolvable, NAMEREQD) is untouched. The test covers both APIs against the same table including WSAGetLastError state, plus the policy path on a valid non-loopback address.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067950864 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2995#pullrequestreview-6067950864). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T02:58:03Z. **Review:** APPROVED --- LGTM — matches real Winsock behavior. `name_info_addr` validates family-specific minimum lengths (16 for AF_INET, 28 for AF_INET6) and distinguishes WSAEFAULT (malformed) from WSAEAFNOSUPPORT (unknown family) — previously every bad sockaddr collapsed into WSAHOST_NOT_FOUND. WSAGetLastError is set on the failure path via wsa_error, and the offline lookup policy (numeric passthrough, loopback resolvable, NAMEREQD) is untouched. The test covers both APIs against the same table including WSAGetLastError state, plus the policy path on a valid non-loopback address.
futurepro62 commented 2026-11-26 05:04:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T04:49:09Z.


Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 306a4b7 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: getnameinfo_reports_winsock_address_errors_instead_of_host_not_found.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7182929755 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2995#issuecomment-7182929755). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T04:49:09Z. --- Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `306a4b7` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `getnameinfo_reports_winsock_address_errors_instead_of_host_not_found`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Marvisak commented 2026-11-26 06:03:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:41:29Z.


Automated triage for the maintainers.

Needs work. name_info_flags (crates/victory-hle/src/modules/net.rs) now parses the sockaddr itself (name_info_addr). For a null, short or unknown-family address it returns WSAEFAULT/WSAEAFNOSUPPORT without calling the host's getnameinfo/GetNameInfoW. The offline guard is not loosened. Valid non-loopback addresses still get NI_NUMERICHOST or WSAHOST_NOT_FOUND, and invalid ones no longer reach the host at all.

What this actually changes is narrow. On main, an invalid address without NI_NAMEREQD already went to the host with NI_NUMERICHOST added, and the host returned the same WSAEFAULT/WSAEAFNOSUPPORT. The only different result is invalid input with NI_NAMEREQD, which now gets the address error instead of WSAHOST_NOT_FOUND. Both are failures, and nothing shows the title passing a malformed sockaddr to these calls. To make this worth merging, please show that the title reaches this case: a log from a title run, or the call site in the title's code. Without that, it is a guard for input the title does not send, and it would be proposed for closing.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183716844 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2995#issuecomment-7183716844). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T05:41:29Z. --- <!-- victory-triage v1 head=306a4b7657a32cc2d7fdb61f498ad969620462f2 verdict=needs-work at=2026-11-26T05:41:17Z --> Automated triage for the maintainers. **Needs work.** `name_info_flags` (`crates/victory-hle/src/modules/net.rs`) now parses the `sockaddr` itself (`name_info_addr`). For a null, short or unknown-family address it returns `WSAEFAULT`/`WSAEAFNOSUPPORT` without calling the host's `getnameinfo`/`GetNameInfoW`. The offline guard is not loosened. Valid non-loopback addresses still get `NI_NUMERICHOST` or `WSAHOST_NOT_FOUND`, and invalid ones no longer reach the host at all. What this actually changes is narrow. On `main`, an invalid address without `NI_NAMEREQD` already went to the host with `NI_NUMERICHOST` added, and the host returned the same `WSAEFAULT`/`WSAEAFNOSUPPORT`. The only different result is invalid input with `NI_NAMEREQD`, which now gets the address error instead of `WSAHOST_NOT_FOUND`. Both are failures, and nothing shows the title passing a malformed `sockaddr` to these calls. To make this worth merging, please show that the title reaches this case: a log from a title run, or the call site in the title's code. Without that, it is a guard for input the title does not send, and it would be proposed for closing. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-26 07:01:00 +00:00
fuzeofficlal commented 2026-11-26 07:01:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T06:09:06Z.


Fair point from triage — without NI_NAMEREQD, main already returns the host's WSAEFAULT/WSAEAFNOSUPPORT, and I have no title-run evidence showing malformed sockaddr inputs with NI_NAMEREQD. Closing to keep the queue focused on higher-impact changes; happy to reopen if a title log ever hits this path.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184141431 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2995#issuecomment-7184141431). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T06:09:06Z. --- Fair point from triage — without `NI_NAMEREQD`, `main` already returns the host's `WSAEFAULT`/`WSAEAFNOSUPPORT`, and I have no title-run evidence showing malformed `sockaddr` inputs with `NI_NAMEREQD`. Closing to keep the queue focused on higher-impact changes; happy to reopen if a title log ever hits this path.

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!2993
No description provided.