Net: connect/WSAConnect with a zero address are refused as off-machine instead of disconnecting a datagram socket #891

Open
opened 2026-11-26 04:14:07 +00:00 by github-bot · 2 comments
Owner

@⁠BastienRodz on GitHub · 2026-11-24 13:33 UTC · original

What's wrong

crates/victory-hle/src/modules/net.rs vets every connect (crates/victory-hle/src/modules/net.rs:223-224) and WSAConnect (crates/victory-hle/src/modules/net.rs:230-239) call through reachable (crates/victory-hle/src/modules/net.rs:147), which rejects any sockaddr that does not parse as a loopback IP with SOCKET_ERROR and WSAENETUNREACH before calling the host.

Under Winsock, a zero address is documented to disconnect a connectionless socket (and fail with WSAEADDRNOTAVAIL on a connection-oriented socket) rather than connect off-machine:

  • connect (Remarks):

    "For a connectionless socket (for example, type SOCK_DGRAM) ... If the address member of the structure specified by name is filled with zeros, the socket will be disconnected."

    "If the address member of the structure specified by the name parameter is filled with zeros, connect will return the error WSAEADDRNOTAVAIL."

  • WSAConnect (Remarks):

    "If the entire name structure is all zeros (not just the address parameter of the name structure), then the socket will be disconnected."

    "If the address parameter of the name structure is all zeroes, WSAConnect will return the error WSAEADDRNOTAVAIL."

With a UDP socket connected to a loopback peer, calling WSAConnect with an all-zero SOCKADDR_IN (or connect with AF_INET 0.0.0.0) returns 0 and disconnects the socket on Windows; VIctory instead returns SOCKET_ERROR with WSAENETUNREACH and leaves the socket connected to the old peer.

Impact

Low impact: a title that disconnects a connected datagram socket to reuse it fails to disconnect and keeps sending to the previous peer. Letting zero-address disconnects reach the host does not weaken the offline policy because a zero address never leaves the machine.

Fix

Add a zero_address helper in crates/victory-hle/src/modules/net.rs that recognizes an all-zero sockaddr as well as AF_INET with 0.0.0.0 and AF_INET6 with ::, and bypass reachable in connect and WSAConnect when it returns true so the call is forwarded to the host as for loopback.

The fix is ready on a branch of my fork, since PR creation is limited to collaborators: https://github.com/BastienRodz/VIctory/commits/hle/zero-address-disconnects (one commit on main ffe310e, net.rs +81/-3).

Tests

  • zero_address_recognises_disconnect_forms: a zeroed sockaddr, 0.0.0.0 and :: count as zero addresses; loopback, 8.8.8.8, ::1, null and short lengths don't.
  • zero_address_disconnects_datagram_socket: a UDP socket connected to a loopback peer, then WSAConnect with an all-zero SOCKADDR_IN, returns 0. A following send fails with WSAENOTCONN, so the socket really is disconnected. connect with AF_INET 0.0.0.0 is passed to the host instead of refused.

On main: the all-zero WSAConnect returns SOCKET_ERROR with WSAENETUNREACH, from reachable, before reaching the host.

On GitHub's windows-latest, with the upstream CI's commands (clippy -D warnings with and without --all-features, then cargo test --workspace --locked), everything passes. That includes both new tests and the existing only_loopback_is_reachable, so the offline policy is unchanged. victory-hle: 96 passed, 0 failed (https://github.com/BastienRodz/VIctory/actions/runs/45404306005).

Under Wine, connect with AF_INET 0.0.0.0 goes through to Linux rather than disconnecting, so the test only checks there that the call isn't refused.

No game data used. AI-assisted: found with GPT-6.2 Astra, written with Gemini 4 Neon, reviewed and verified with Claude Code.

**@⁠BastienRodz** on GitHub · 2026-11-24 13:33 UTC · [original](https://github.com/Marvisak/VIctory/issues/891) ## What's wrong `crates/victory-hle/src/modules/net.rs` vets every `connect` (`crates/victory-hle/src/modules/net.rs:223-224`) and `WSAConnect` (`crates/victory-hle/src/modules/net.rs:230-239`) call through `reachable` (`crates/victory-hle/src/modules/net.rs:147`), which rejects any `sockaddr` that does not parse as a loopback IP with `SOCKET_ERROR` and `WSAENETUNREACH` before calling the host. Under Winsock, a zero address is documented to disconnect a connectionless socket (and fail with `WSAEADDRNOTAVAIL` on a connection-oriented socket) rather than connect off-machine: - [`connect`](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect) (Remarks): > "For a connectionless socket (for example, type SOCK_DGRAM) ... If the address member of the structure specified by *name* is filled with zeros, the socket will be disconnected." > > "If the address member of the structure specified by the *name* parameter is filled with zeros, **connect** will return the error WSAEADDRNOTAVAIL." - [`WSAConnect`](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaconnect) (Remarks): > "If the entire name structure is all zeros (not just the address parameter of the name structure), then the socket will be disconnected." > > "If the address parameter of the *name* structure is all zeroes, **WSAConnect** will return the error WSAEADDRNOTAVAIL." With a UDP socket connected to a loopback peer, calling `WSAConnect` with an all-zero `SOCKADDR_IN` (or `connect` with `AF_INET` `0.0.0.0`) returns `0` and disconnects the socket on Windows; VIctory instead returns `SOCKET_ERROR` with `WSAENETUNREACH` and leaves the socket connected to the old peer. ## Impact Low impact: a title that disconnects a connected datagram socket to reuse it fails to disconnect and keeps sending to the previous peer. Letting zero-address disconnects reach the host does not weaken the offline policy because a zero address never leaves the machine. ## Fix Add a `zero_address` helper in `crates/victory-hle/src/modules/net.rs` that recognizes an all-zero `sockaddr` as well as `AF_INET` with `0.0.0.0` and `AF_INET6` with `::`, and bypass `reachable` in `connect` and `WSAConnect` when it returns `true` so the call is forwarded to the host as for loopback. The fix is ready on a branch of my fork, since PR creation is limited to collaborators: https://github.com/BastienRodz/VIctory/commits/hle/zero-address-disconnects (one commit on `main` `ffe310e`, `net.rs` +81/-3). ## Tests - `zero_address_recognises_disconnect_forms`: a zeroed `sockaddr`, `0.0.0.0` and `::` count as zero addresses; loopback, `8.8.8.8`, `::1`, null and short lengths don't. - `zero_address_disconnects_datagram_socket`: a UDP socket connected to a loopback peer, then `WSAConnect` with an all-zero `SOCKADDR_IN`, returns 0. A following `send` fails with `WSAENOTCONN`, so the socket really is disconnected. `connect` with `AF_INET` `0.0.0.0` is passed to the host instead of refused. **On `main`:** the all-zero `WSAConnect` returns `SOCKET_ERROR` with `WSAENETUNREACH`, from `reachable`, before reaching the host. On GitHub's `windows-latest`, with the upstream CI's commands (clippy `-D warnings` with and without `--all-features`, then `cargo test --workspace --locked`), everything passes. That includes both new tests and the existing `only_loopback_is_reachable`, so the offline policy is unchanged. `victory-hle`: 96 passed, 0 failed (https://github.com/BastienRodz/VIctory/actions/runs/45404306005). Under Wine, `connect` with `AF_INET` `0.0.0.0` goes through to Linux rather than disconnecting, so the test only checks there that the call isn't refused. No game data used. AI-assisted: found with GPT-6.2 Astra, written with Gemini 4 Neon, reviewed and verified with Claude Code.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:07 +00:00
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-24 14:08 UTC · original

Independent Windows 11 verification of 5d66c30 (BastienRodz/VIctory@hle/zero-address-disconnects, fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):

  • cargo test -p victory-hle: 96 passed, 0 failed (plus no_dll_planting: 1 passed), including both new tests modules::net::tests::zero_address_recognises_disconnect_forms and modules::net::tests::zero_address_disconnects_datagram_socket (and only_loopback_is_reachable stays green)
  • cargo clippy -p victory-hle --all-targets: 0 warnings
  • cargo xtask policy: ok

Confirmed that zero_address passes zero-address disconnects cleanly to host Winsock without weakening the offline loopback policy.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-24 14:08 UTC · [original](https://github.com/Marvisak/VIctory/issues/891#issuecomment-7133905390) Independent Windows 11 verification of `5d66c30` (`BastienRodz/VIctory@hle/zero-address-disconnects`, fast-forward on `main` `ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC): - `cargo test -p victory-hle`: **96 passed, 0 failed** (plus `no_dll_planting`: 1 passed), including both new tests `modules::net::tests::zero_address_recognises_disconnect_forms` and `modules::net::tests::zero_address_disconnects_datagram_socket` (and `only_loopback_is_reachable` stays green) - `cargo clippy -p victory-hle --all-targets`: **0 warnings** - `cargo xtask policy`: ok Confirmed that `zero_address` passes zero-address disconnects cleanly to host Winsock without weakening the offline loopback policy. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:56 UTC · original

Automated triage for the maintainers.

Confirmed on main. In crates/victory-hle/src/modules/net.rs, connect, WSAConnect and the other connect paths go through reachable, which lets only a loopback address through. An all-zero sockaddr or 0.0.0.0 / :: is refused with WSAENETUNREACH before the host sees it, so a datagram socket can't be disconnected. Open PR #2066 ("Net: forward zero-address datagram disconnects", which names this issue) carries the change, so review can continue there. Your branch hle/zero-address-disconnects can be compared with it.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:56 UTC · [original](https://github.com/Marvisak/VIctory/issues/891#issuecomment-7155315745) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T14:08:33Z at=2026-11-25T06:56:21Z --> Automated triage for the maintainers. Confirmed on `main`. In `crates/victory-hle/src/modules/net.rs`, `connect`, `WSAConnect` and the other connect paths go through `reachable`, which lets only a loopback address through. An all-zero `sockaddr` or `0.0.0.0` / `::` is refused with `WSAENETUNREACH` before the host sees it, so a datagram socket can't be disconnected. Open PR #2066 ("Net: forward zero-address datagram disconnects", which names this issue) carries the change, so review can continue there. Your branch `hle/zero-address-disconnects` can be compared with it. --- _Generated by [Claude Code](https://claude.ai/code)_
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#891
No description provided.