WSAConnectByList reads at most 64 candidates and refuses a negative count #466

Open
Frtuchinno wants to merge 1 commit from upstream-pr/466 into main
Frtuchinno commented 2026-11-25 01:17:22 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Frtuchinno on 2026-11-25T01:17:22Z.


Fixes #428.

WSAConnectByList took the title's iAddressCount as the length of a slice with no upper bound. A count larger than the number of entries actually present made the vetting loop read whatever memory follows the list as SOCKET_ADDRESS values. A negative count became 0, so the list went on to the host without being vetted.

Change (crates/victory-hle/src/modules/net.rs):

  • A count below zero or above MAX_CONNECT_CANDIDATES (64) fails with WSAEINVAL and the call returns FALSE. Nothing after the count is read, and the host never sees the list. Every candidate has to be loopback, and the host tries them one after another, so a legitimate list is a handful of entries.
  • Entries are read one by one with read_unaligned instead of through a &[SocketAddress]. The loop still stops at the first candidate that isn't loopback (WSAENETUNREACH), as before.

Test: connect_by_list_vets_a_bounded_list covers five lists:

List Result
65 loopback entries WSAEINVAL
count i32::MAX with one entry present WSAEINVAL
count -1 WSAEINVAL
loopback entry + TEST-NET entry WSAENETUNREACH
a single loopback entry the host connects to a local listener

On the old code the 65-entry case reaches the host and connects (left: 1, right: 0), so the test fails there.

Checked on Windows 11 (RX 7800 XT), toolchain 1.98.1 on a803c87:

  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean, with and without --all-features.
  • cargo test -p victory-hle --locked: 97 passed, 0 failed.

No game run: this path isn't reached by the title's normal boot. Only net.rs changes. Running cargo fmt on main also reformats twelve other files in this crate, and those are left out of this PR.

AI-assisted (Claude Code): it wrote the change and the test and ran the checks on my machine. I reviewed it before opening this PR.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594877911 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/466). Originally posted by [Frtuchinno](https://github.com/Frtuchinno) on 2026-11-25T01:17:22Z. --- Fixes #428. `WSAConnectByList` took the title's `iAddressCount` as the length of a slice with no upper bound. A count larger than the number of entries actually present made the vetting loop read whatever memory follows the list as `SOCKET_ADDRESS` values. A negative count became 0, so the list went on to the host without being vetted. **Change** (`crates/victory-hle/src/modules/net.rs`): - A count below zero or above `MAX_CONNECT_CANDIDATES` (64) fails with `WSAEINVAL` and the call returns FALSE. Nothing after the count is read, and the host never sees the list. Every candidate has to be loopback, and the host tries them one after another, so a legitimate list is a handful of entries. - Entries are read one by one with `read_unaligned` instead of through a `&[SocketAddress]`. The loop still stops at the first candidate that isn't loopback (`WSAENETUNREACH`), as before. **Test:** `connect_by_list_vets_a_bounded_list` covers five lists: | List | Result | |---|---| | 65 loopback entries | `WSAEINVAL` | | count `i32::MAX` with one entry present | `WSAEINVAL` | | count `-1` | `WSAEINVAL` | | loopback entry + TEST-NET entry | `WSAENETUNREACH` | | a single loopback entry | the host connects to a local listener | On the old code the 65-entry case reaches the host and connects (`left: 1, right: 0`), so the test fails there. **Checked on** Windows 11 (RX 7800 XT), toolchain 1.98.1 on `a803c87`: - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`: clean, with and without `--all-features`. - `cargo test -p victory-hle --locked`: 97 passed, 0 failed. No game run: this path isn't reached by the title's normal boot. Only `net.rs` changes. Running `cargo fmt` on `main` also reformats twelve other files in this crate, and those are left out of this PR. AI-assisted (Claude Code): it wrote the change and the test and ran the checks on my machine. I reviewed it before opening this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/466:upstream-pr/466'
git switch 'upstream-pr/466'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/466'
git switch 'upstream-pr/466'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/466'
git switch 'upstream-pr/466'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/466'
git switch 'main'
git merge --squash 'upstream-pr/466'
git switch 'main'
git merge --ff-only 'upstream-pr/466'
git switch 'main'
git merge 'upstream-pr/466'
git push origin 'main'
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!466
No description provided.