fix(libc): fail fputs, fputc and fprintf on a closed stream as a PS5 does #22047
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22047"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-17T03:06:28Z.
What
A write to a stream that
fcloseor a failedfreopenclosed seterrnotoEBADFinfputs,fputcandfprintf. On a PS5fputsandfputcreturn -1 and leaveerrnounchanged, andfprintffails withEINVAL(#9763; thefreopen of a closed streamentry indocs/dev/debt/libc.md).putc,putcharand__swbufforward tofputcand follow it.fwrite,puts,printfand the wide forms) were not measured and keepEBADF; the debt entry says so.GuestStandardStreams.cppandGuestFreopenHostStandard.cppcheck the measured results where they checkedEBADFbefore.Tested
Linux (Debian 13, GCC 14.2.0, Release), on
mainec7369ecb8.ctest -R '^guest_(standard_streams.*|freopen_host_standard)$': 6/6 passed.main's sources and this branch's tests,guest_standard_streams,guest_standard_streams_closed_stdoutandguest_freopen_host_standardfail (errno9).ctest(5896 tests,-j 12) with this branch and my other twelve branches of this round merged ontomain521fb7fec4: 5880 passed. The 16 failures are the set that fails onmainin the same environment: sixagc_drivercases (agc_driver_image_table_packed_guardspasses when run on its own) and ten that need a.gitdirectory, network or a passwd entry for the user.python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branch: failed closed on #7447, #8150, #9087, #9340, #9526, #11332, #12184, #12682, #12688, #12700 and #12965, which conflict withmain; none of their diffs touches the closed-stream checks offputs,fputcorfprintf.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T03:10:09Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
117239034b:tools/check_conventions.pypassed.guest_freopen_host_standard_tests,guest_standard_stream_testsbuilt cleanly.guest_standard_streams,guest_standard_streams_closed_stdout,guest_standard_streams_exclusive_stdout,guest_standard_streams_reopen_closed_stdout,guest_standard_streams_update_stdout,guest_freopen_host_standard):core/libs/prx/libc/src/FileAndHeap.cpp,core/libs/prx/libc/src/Formatting.cpp,core/libs/prx/libc/src/StandardStreams.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T08:42:18Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed behavior is consistent with the stated closed-stream errno results in the inspected implementation and tests.
What I ran
Reviewed head
117239034be43795aa9f157cb58a35e87de74dcc. No commands or tests were run; the reader exposes file reads only.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The prepared bundle marks all six changed files as included, but reads using
review/files/<path>were not served by the reader. I inspected the complete diff and targeted ranges in the three implementation files andGuestStandardStreams.cpp; full contents ofGuestFreopenHostStandard.cppand the debt note, and the rest of the changed files, were not read.files.jsonwas not available. Tests and author-reported environment/results were not independently verified. The inspected files wereFileAndHeap.cpp,Formatting.cpp,StandardStreams.cpp, andGuestStandardStreams.cpp; no files were excluded by rule according to the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T15:23:47Z.
Review: APPROVED
Reviewed — looks good
The reviewed code changes the closed stream behavior of
fputs,fputc, andfprintfand updates tests to assert the documented errno results; I found no verified blocking defect.What I ran
Read the prepared diff and all six changed source and test files plus the new debt note at head
1d3137ca095f599251679fdb1825c3af71473cbf, usingrepo_read.py.No commands or tests were run. The test and negative control results in the PR description are author reported.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read every file listed in the manifest; none were excluded. I did not independently verify the PS5 measurements, run tests, or inspect callers beyond the changed functions and tests. The author reports Linux test results and says Windows and macOS were not tested.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:23:52Z.
Review: COMMENTED
Built the submitted stream and formatting sources and ran all three Linux fixtures.
FileStreams,GuestFreopenHostStandard, andGuestStandardStreamspassed. The new cases check the return anderrnobehavior forfputs,fputcandfprintfon closed streams.AI-assisted: yes.