fix(libc): fail fgets with EINVAL and the error indicator for a size of 0 or less #2711
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2711"
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 husseinkad on 2026-10-10T11:53:48Z.
What
The guest
fgetshanded the size straight to the host. On Windows a size of 0 returned NULL witherrnountouched and no stream error indicator, and a negative size got a Windows-runtimeerrnobut no indicator. FreeBSD'slib/libc/stdio/fgets.c(releng/11.4 andmain) handlesn <= 0before reading anything: it sets__SERRon the stream, setserrno = EINVALand returns NULL, leaving the buffer and the file position untouched;fgetwsis defined the same way.fgets_nid_postfixnow does the same forsize <= 0:SetEncodingError()(whatferrorandclearerrread, sticky untilclearerr, like__SERR),errno = 22, NULL, buffer and position untouched. Sizes of 1 and more go to the host exactly as before. The repo has onlyfgetsamong the fgets-like exports, so there is no sibling to change.Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:
guest_standard_streamsgains sizes 0, -1 and INT32_MIN (return NULL,errno22, buffer unchanged,ftello0,ferrorset and cleared byclearerr) and size 1 as a control (writes the NUL, reads nothing). It fails without the change (exit0xc0000409) and passes with it;ctest -R "guest_standard_streams|file_streams"passes.main's and this branch'sfgetsside by side: 336 combinations (8 sizes from INT_MIN to INT_MAX x 21 stream scenarios: regular, empty, at EOF, write-only, closed, redirected stdin in text and binary mode, pendingungetc, stream already in error, CRLF, embedded NUL, content longer than the buffer or exactly size-1 bytes x twoerrnopresets): the 210 combinations with size 1 or more are byte-identical (return value, buffer, position,errno, flags, follow-up reads); the 116 differing combinations of size 0 or less are exactly the intended change.tools/check_conventions.py --base origin/mainpasses;tools/pr_overlap.py --branchreports no overlap.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T11:53:58Z.
Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
Pull request closed