Skip to content

fix(libSceHttp): validate the id of the send, receive, resolve, block size, header size and content length setters - #24528

Open
AlfaRojo wants to merge 4 commits into
boykopovar:mainfrom
AlfaRojo:fix/http-setters-validate-id
Open

AlfaRojo wants to merge 4 commits into
boykopovar:mainfrom
AlfaRojo:fix/http-setters-validate-id

Conversation

@AlfaRojo

Copy link
Copy Markdown
Contributor

What

sceHttpSetSendTimeOut, sceHttpSetRecvTimeOut, sceHttpSetResolveTimeOut, sceHttpSetResolveRetry, sceHttpSetRecvBlockSize, sceHttpSetResponseHeaderMaxSize and sceHttpSetRequestContentLength returned 0 for any id, before sceHttpInit too, and kept nothing. They now live in core/libs/prx/libSceHttp/src/Options.cpp:184-219 next to the other option setters and:

  • return ERROR_BEFORE_INIT until sceHttpInit;
  • return ERROR_INVALID_ID for an unknown or deleted id;
  • keep the value in the object's HttpOptions (new fields in Options.hpp), copied from the parent as the existing options are;
  • sceHttpSetRequestContentLength takes only a request (new HttpOptions::request, set by the four sceHttpCreateRequest* calls) and refuses a template or connection with ERROR_INVALID_ID;
  • sceHttpSetResolveRetry refuses a negative count and sceHttpSetResolveTimeOut refuses 999999 us or less when the title was built with SDK 1.70 or later, both with ERROR_INVALID_VALUE before the id check.

Evidence and limits (also in the debt fragment). The firmware 13.42 disassembly in docs/dev/debt/libSceHttp.md is recorded only for sceHttpSetHttp09Enabled, sceHttpSetPriorityOption and sceHttpSetPolicyOption ("checks initialisation, then stores each value through one option setter that refuses an unknown id"); I did not disassemble these seven, so I apply the same order to them as an inference. Which kinds each takes and the two value checks come from shadPS4 src/core/libraries/network/http.cpp at 264d6b71d8 (sceHttpSetSendTimeOut 3017, sceHttpSetRecvTimeOut 3034, sceHttpSetResolveTimeOut 2665, sceHttpSetResolveRetry 2978, sceHttpSetRecvBlockSize 2186, sceHttpSetResponseHeaderMaxSize 2689, sceHttpSetRequestContentLength 2913): PS4, not measured on a PS5. No merged PR or issue measures these calls on a console. shadPS4's busy error for a request already sent is not modelled (no request is ever sent), and the content length given to sceHttpCreateRequest* is still ignored. Defaults (0) are unmeasured. shadPS4 code was not copied.

The debt fragment docs/dev/debt/changes/fix-http-setters-validate-id.md removes the seven from the Silent stubs entries (rewriting the sceHttpSetResponseHeaderMaxSize/sceHttpSetRecvBlockSize one, dropping the send/receive/content-length, resolve-retry and resolve-timeout ones), notes that sceHttpSetConnectTimeOut still does not check its id, and adds one entry with the above.

Tested

Windows 11, WinLibs GCC 15.2, Release, -DBUILD_TESTING=ON; offline guest tests only, no title or console.

  • core/libs/tests/GuestHttpOptions.cpp: new CheckStoredLimits (line 284) covers, for a template, connection and request, every setter's success and stored value (including 0 and values above 2^31 and 2^32), BEFORE_INIT before sceHttpInit (CheckOfflineSettersBeforeInit), unknown, context and deleted ids, content length refused on a template and connection and not kept, the negative retry, the sub-second resolve timeout at SDK 1.70 and the same value accepted at SDK 1.6FFFFF, and the value check coming before the id check.
  • core/libs/tests/GuestHttp.cpp: the two calls that expected 0 after the last sceHttpTerm now expect BEFORE_INIT.
  • RED on main: with src/ restored to upstream/main and the tests as in this PR, ninja tests/guest_http_options_tests.exe fails ("'const struct HttpOptions' has no member named 'sendTimeoutUs'") and ctest -R "^guest_http$" aborts (Exit code 0xc0000409) because the stubs returned 0 after sceHttpTerm.
  • GREEN with the change: ctest -R "guest_http_|guest_http$" -E http2 in a build of all guest_http_*_tests: 20/20 passed.
  • py -3 tools/check_conventions.py --base upstream/main: all checks passed; py -3 tools/debt_fold.py --check: no output.
  • Open PRs feat(libSceHttp): add synchronous HTTP request transport #9834 and fix(http): trust the system CA list for HTTPS requests #11134 (HTTP transport) touch the AddHttpChild(id, conn_id) lines this PR changes; neither changes the seven setters.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

AlfaRojo and others added 3 commits November 20, 2026 12:39
… size, header size and content length setters

sceHttpSetSendTimeOut, sceHttpSetRecvTimeOut, sceHttpSetResolveTimeOut,
sceHttpSetResolveRetry, sceHttpSetRecvBlockSize,
sceHttpSetResponseHeaderMaxSize and sceHttpSetRequestContentLength returned
0 for any id and kept nothing. They now return BEFORE_INIT before
sceHttpInit, INVALID_ID for an unknown id, and keep the value in the
object's options; the content length is taken only by a request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 9fba7a84b1:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_http_options_tests, guest_http_tests built cleanly.
  • CTest (guest_http, guest_http_uri_locale, guest_http_options):
    1/3 Test #3934: guest_http_uri_locale ............   Passed    0.04 sec
    2/3 Test #3937: guest_http_options ...............   Passed    0.03 sec
    3/3 Test #3932: guest_http .......................   Passed    0.34 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libSceHttp/Export.cpp, core/libs/prx/libSceHttp/src/Options.cpp, core/libs/prx/libSceHttp/src/Options.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceHttp/src/Options.cpp: Verified that sceHttpSetSendTimeOut, sceHttpSetRecvTimeOut, sceHttpSetResolveTimeOut, sceHttpSetResolveRetry, sceHttpSetRecvBlockSize, sceHttpSetResponseHeaderMaxSize, and sceHttpSetRequestContentLength check HttpInitialised() first and return ERROR_BEFORE_INIT (0x80431020) if uninitialized.
    • core/libs/prx/libSceHttp/src/Options.cpp: Verified order of validation in sceHttpSetResolveRetry (retry < 0 checks before id lookup) and sceHttpSetResolveTimeOut (SDK version check >= 0x01700000u with usec <= 999999u returning ERROR_INVALID_VALUE before id lookup).
    • core/libs/prx/libSceHttp/src/Options.cpp: Verified SetHttpRequestContentLength checks both ID presence and that options.request is true, returning ERROR_INVALID_ID when passed templates or connections.
    • core/libs/prx/libSceHttp/Export.cpp: Verified all four request creation entry points (sceHttpCreateRequest, sceHttpCreateRequest2, sceHttpCreateRequestWithURL, sceHttpCreateRequestWithURL2) pass request=true to AddHttpChild.
    • core/libs/prx/libSceHttp/src/Options.cpp: Verified thread-safety and lock scoping of g_optionsMutex across SetHttpValue, SetHttpRequestContentLength, AddHttpChild, and RemoveHttpObject.
    • docs/dev/debt/changes/fix-http-setters-validate-id.md: Verified technical debt fragment correctly records unknown function info, behaviour differences, and removed stubs conforming to AGENTS.md rules.

Looks Good To Me

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 9fba7a84b19af3723723122569b2b60df38830ed using the prepared diff and pinned repo_read.py reader. No commands or tests were run during this review.

Results

Check Result Note
Changed code review passed All six changed files read
Tests in this review not run Author-reported runs not repeated
Excluded files not applicable manifest.json lists no excluded changed files

Findings

Blocking

None.

Non-blocking

None.

Not verified

No runtime checks were performed. The author reports 20/20 guest HTTP tests and convention checks passing; those results were not independently run. Console behavior and the PS5 firmware behavior inferred from shadPS4 were not verified. files.json was not available through the reader; exclusion status was checked in manifest.json.

Files read: description.md, commits.md, manifest.json, diff.patch; Export.cpp, Options.cpp, Options.hpp, GuestHttp.cpp, GuestHttpOptions.cpp, and fix-http-setters-validate-id.md. All six changed files were listed as included in manifest.json and read. No files were listed as excluded.

To get this to a good state

Nothing is required. The PS5 behavior inference and lack of console measurements are documented limitations.

@ge9x0

ge9x0 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Linux run (the Tested section lists Windows only).

Setup: Fedora 44, kernel 7.3.4, GCC 16.2.1, glibc from F44, Release. Head 9fba7a84b1 merged with --no-ff onto main e481b13555 (clean); the baseline is e481b13555 in the same build directory.

Result: 43 tests matching the files this PR changes: all passed on the merge (43/43). The same pattern on main passed as well (43 of these exist there), and the whole pattern run (tests of this and 14 other PRs) had no failures on either arm.

AI-assisted: yes

@ycbuzi

ycbuzi commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Tested 9fba7a84b1 merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 2 tests failed out of 6505; 99% tests passed, 2 tests failed out of 6505. 2 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 6505; 100% tests passed, 0 tests failed out of 6505. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 9834 core/libs/prx/libSceHttp/Export.cpp
core/libs/tests/GuestHttp.cpp
PR 11134 core/libs/prx/libSceHttp/Export.cpp
core/libs/tests/GuestHttp.cpp
PR 26370 core/libs/prx/libSceHttp/src/Options.cpp

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 81b4bc374f321fb0f2cc50861e84918de923ddd6 from the prepared diff and targeted source reads. No tests or builds were run; repo_read.py was not invoked directly because this review interface provides pinned-head reader tools.

Results

Check Result Note
Diff and targeted source review passed Six changed files read
Tests and build not run Author-reported results only
Review-bundle exclusions not applicable files.json was not available in the bundle

Findings

Blocking

None.

Non-blocking

  • The new timeout and size values are stored, but the debt note says no code currently reads them and their defaults are unmeasured. The description accurately identifies these limits; consider tracking behavioral use and validation separately. See core/libs/prx/libSceHttp/src/Options.cpp:197.
  • The resolve-timeout and retry validation order and thresholds are inferred from shadPS4 rather than measured on PS5 firmware, as the description and debt note disclose. See core/libs/prx/libSceHttp/src/Options.cpp:207.

Not verified

No tests, build, console behavior, or firmware disassembly were verified in this review. The bundle included the full text of all six changed files, and all six were read: core/libs/prx/libSceHttp/Export.cpp, core/libs/prx/libSceHttp/src/Options.cpp, core/libs/prx/libSceHttp/src/Options.hpp, core/libs/tests/GuestHttp.cpp, core/libs/tests/GuestHttpOptions.cpp, and docs/dev/debt/changes/fix-http-setters-validate-id.md. files.json was unavailable, so the reviewed-file list could not be compared with a separate reviewed manifest.

To get this to a good state

Nothing is required. The optional follow-up is to measure or confirm the inferred PS5 behavior and connect stored options to behavior when HTTP requests are implemented.

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built the changed HTTP units and ran the branch's GuestHttp and GuestHttpOptions fixtures against the existing Linux runtime. Both passed. I checked that the seven setters accept live handles of the supported kinds and route invalid IDs through the shared validation path.

AI-assisted: yes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants