test(libkernel): cover socket options negative length and invalid protocol level bounds #14472

Merged
slopgobblercobbler merged 1 commit from upstream-pr/14472 into main 2026-11-13 11:02:31 +00:00
slopgobblercobbler commented 2026-11-01 14:52:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-11-01T14:52:25Z.


What

Enhances socket option boundary and error condition test coverage in core/libs/tests/GuestSocketStreamOptions.cpp:

  • Tests setsockopt with invalid protocol levels (-1, 1, 2, 17, 99, 1234, 0x10000) returning EINVAL (22).
  • Tests setsockopt with negative lengths (static_cast<std::uint32_t>(-1) and -4) returning EINVAL (22).
  • Tests unsupported protocol options under TcpLevel and SocketLevel with negative length returning ENOPROTOOPT (42).
  • Validates negative length and invalid protocol level rejection across stream sockets, datagram sockets, unix domain local sockets, and dual-stack IPv6 sockets.

Tested

  • Built and ran GuestSocketStreamOptions.cpp locally against FreeBSD socket option emulation: exited cleanly with code 0.
  • python tools/check_conventions.py --base upstream/main --head HEAD: 0 findings.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5108488458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14472). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-01T14:52:25Z. --- ### What Enhances socket option boundary and error condition test coverage in `core/libs/tests/GuestSocketStreamOptions.cpp`: - Tests `setsockopt` with invalid protocol levels (-1, 1, 2, 17, 99, 1234, 0x10000) returning `EINVAL` (22). - Tests `setsockopt` with negative lengths (`static_cast<std::uint32_t>(-1)` and `-4`) returning `EINVAL` (22). - Tests unsupported protocol options under `TcpLevel` and `SocketLevel` with negative length returning `ENOPROTOOPT` (42). - Validates negative length and invalid protocol level rejection across stream sockets, datagram sockets, unix domain local sockets, and dual-stack IPv6 sockets. ### Tested - Built and ran `GuestSocketStreamOptions.cpp` locally against FreeBSD socket option emulation: exited cleanly with code 0. - `python tools/check_conventions.py --base upstream/main --head HEAD`: 0 findings. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-02 05:15:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T05:15:34Z.

Review: COMMENTED


Reviewed — no blocking findings

The new assertions use the setsockopt entry point at base, which rejects any level other than socket level, IP, TCP and IPv6 with EINVAL (Socket/src/Udp.cpp lines 1305-1307). The unknown-level cases in the test match that rule. I did not trace the TCP-option-on-datagram and negative-length cases through the option dispatch (SocketOptions.cpp), so those are not verified here. Test-only change. The hosted Windows CTest run had one case, a tool check; the stream options test did not run there.

What I ran

  • Head bb36e9baf3d3c24dd5f9593676e6681c46ab192b; base e450145140... (the base moved since the first review; the diff is against the PR's own base). 1 file, +21/-0: core/libs/tests/GuestSocketStreamOptions.cpp.
  • Read the diff and the setsockopt_nid_postfix entry point at base (Socket/src/Udp.cpp lines 1300-1312).
  • Read-only checks from the trusted main checkout (precheck not run: no PR-head code is run here): diff check, conventions and the stack check passed; the ABI audit is not applicable.
  • Hosted: Windows CTest passed 1 of 1 cases, a tool check; the stream options test was not in the run.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed depends on none; the stack check passed
Unknown levels return EINVAL passed Udp.cpp lines 1305-1307
TCP option on a datagram socket (Invalid) not traced the dispatch in SocketOptions.cpp was not read
Negative length cases not traced the length checks in SocketOptions.cpp were not read
Hosted Windows CTest not run one tool case only
Build and runtime tests not run no local build
Negative controls not run no local build
Hosted CI passed windows passed; linux and relinkers skipped
Read-only check output

Precheck was not run: no PR-head code is run here. Conventions: passed. Hosted: gh api repos/boykopovar/AnyPS5/commits/bb36e9baf3d3c24dd5f9593676e6681c46ab192b/check-runs.

Negative control

Not run here. A negative control needs a build, and code from this head is not run here.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

  • The TCP-on-datagram and negative-length expectations were not traced through SocketOptions.cpp.
  • The stream options test did not run hosted.

To get this to a good state

  • Nothing blocking. A run of the stream options test on the hosted runner would confirm the expectations.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732354148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14472#pullrequestreview-5732354148). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T05:15:34Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The new assertions use the `setsockopt` entry point at base, which rejects any level other than socket level, IP, TCP and IPv6 with EINVAL (`Socket/src/Udp.cpp` lines 1305-1307). The unknown-level cases in the test match that rule. I did not trace the TCP-option-on-datagram and negative-length cases through the option dispatch (`SocketOptions.cpp`), so those are not verified here. Test-only change. The hosted Windows CTest run had one case, a tool check; the stream options test did not run there. ## What I ran - Head `bb36e9baf3d3c24dd5f9593676e6681c46ab192b`; base `e450145140...` (the base moved since the first review; the diff is against the PR's own base). 1 file, +21/-0: `core/libs/tests/GuestSocketStreamOptions.cpp`. - Read the diff and the `setsockopt_nid_postfix` entry point at base (`Socket/src/Udp.cpp` lines 1300-1312). - Read-only checks from the trusted main checkout (precheck not run: no PR-head code is run here): diff check, conventions and the stack check passed; the ABI audit is not applicable. - Hosted: Windows CTest passed 1 of 1 cases, a tool check; the stream options test was not in the run. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | depends on none; the stack check passed | | Unknown levels return EINVAL | passed | `Udp.cpp` lines 1305-1307 | | TCP option on a datagram socket (`Invalid`) | not traced | the dispatch in `SocketOptions.cpp` was not read | | Negative length cases | not traced | the length checks in `SocketOptions.cpp` were not read | | Hosted Windows CTest | not run | one tool case only | | Build and runtime tests | not run | no local build | | Negative controls | not run | no local build | | Hosted CI | passed | windows passed; linux and relinkers skipped | <details><summary>Read-only check output</summary> Precheck was not run: no PR-head code is run here. Conventions: passed. Hosted: `gh api repos/boykopovar/AnyPS5/commits/bb36e9baf3d3c24dd5f9593676e6681c46ab192b/check-runs`. </details> ## Negative control Not run here. A negative control needs a build, and code from this head is not run here. ## Findings **Blocking** None. **Non-blocking** None. ## Sources - Changed test: https://github.com/boykopovar/AnyPS5/blob/bb36e9baf3d3c24dd5f9593676e6681c46ab192b/core/libs/tests/GuestSocketStreamOptions.cpp - Entry point: https://github.com/boykopovar/AnyPS5/blob/f2d874c1fdccf781c0fa5d86619bb5dd8894b958/core/libs/prx/libkernel/Socket/src/Udp.cpp#L1300-L1307 ## Not verified - The TCP-on-datagram and negative-length expectations were not traced through `SocketOptions.cpp`. - The stream options test did not run hosted. ## To get this to a good state - Nothing blocking. A run of the stream options test on the hosted runner would confirm the expectations.
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
boykopovar/AnyPS5!14472
No description provided.