fix(libc): preserve errno on string scan input exhaustion #13012
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13012"
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 JJenkx on 2026-10-29T21:29:47Z.
What
On glibc,
sscanf("", "%s", buffer)returnsEOFand clears an incomingerrnoof 97 to zero. Thelibc.prxmodules bundled with PPSA03766 and PPSA07923 preserve 97. The same mismatch affectsvsscanfand empty/whitespace input for other directives.Preserve the incoming value when the glibc scanner returns
EOFwitherrno == 0. A nonzero error reported by the host is retained. The change is limited to the glibc call inHostVsscanf; parsing, assignments and non-glibc calls retain their existing paths. The regression checks both exported entry points, untouched destinations, suppressed conversions, several incoming values and anERANGEconversion.Tested
Linux x86-64 (7.2.9-arch1-1), actual independent Release
libcbuild at8a7cd7d35a333f4500d6bdf32b07ffaa33d3a407.guest_formatting,guest_wide_formatting,guest_safe_errors: 3/3 pass, no skips. The new formatting fixture linked against unchanged main951f374c871fails withFormatting check failed(CTest exit 8).errno. The built change matches all 420 rows, fixing 64 with zero regressions. Range errors remain intact. Probe processes reject loaded AGC/VideoOut/Vulkan libraries.c40cef843681418b4d66df2939a92ba8ba6ba5d9. Overlap scan reports no positive source/test/export overlaps. Five same-file peers cannot merge into that base; their shared hunks concern separate stream/wide/formatting behavior rather than this EOF error-state guard.Probe source, synthetic rows, build/test and negative-control evidence, SHA-256
4abe9d7857c4d7795889dc7495e1ae5c9c8f28223b3ada53e210124e69c8423f(download verified). Attachment contains no SDK binaries or game assets.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)Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T21:37:45Z.
Review: COMMENTED
Host-only review of
8a7cd7d35a. The fix looks right. I'm leaving this as a comment rather than an approval until thewindowslane finishes.Reproduction. I wrote standalone C probes that use your row matrix:
""," "," "×%s %d %f %*s× saved errno 0/22/97, plus the1e99999row.vsscanffails 24/36 rows. EveryEOFclears errno to 0. With your guard it fails 0/36, and the range row still ends with errno 34.vsscanfalready passes 36/36. That fits limiting the change to the__GLIBC__branch.Guard mutants on glibc.
result == EOFonly anderrno == 0only both survive the new test. The no-op guard is caught (24 rows). I couldn't find an input where the two one-sided mutants behave differently from your guard: match failure returns 0, partial-then-EOF returns 1, literal-only empty input returns -1 with errno kept,%non empty input returns 0, and invalid%lsunder C.UTF-8 returns 0 with errno 84. So they look equivalent in practice. Nothing to change here.Possible follow-up (not for this PR). glibc
fscanfshows the same clearing. From errno 97, a whitespace-onlyfmemopenstream and an emptytmpfile()both give -1 with errno 0.HostVfscanf(Formatting.cpp:133) is still unguarded and feeds the guest stream scan exports (Formatting.cpp:479, :808). Your bundled-module probe could probably measure the stream path the same way, before anyone extends the guard there.Windows. On Windows the new test goes through
ScanWindows→ UCRTvsscanf("%lld%n"). Under Wine's UCRT, whitespace-only%d/%freturns 0 rather than EOF, and%foverflow leaves errno at 0. Wine also leaves errno at 0 for the existing%doverflow row (test line 174 expects 34), and that row passes on the real windows lane. So I don't trust Wine here. Thewindowsjob on this head is the real check, and it's still pending.Conventions and intake checks pass. No code comments, and the change is generic.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T21:39:19Z.
Review: APPROVED
Reviewed — looks good
The glibc-only wrapper restores the prior
errnoonly when scanning returnsEOFwith hosterrnoleft at zero; regression cases cover both exported entry points and verify that nonzero conversion errors remain intact.What I ran
Reviewed head
8a7cd7d35a333f4500d6bdf32b07ffaa33d3a407against current upstreammain52f212ec053f917455f2f87674ddb708dcc545d8; the merge preview is clean. The PR's base currently points tofc9240dbc5dc89a6b17a739703e00d26318c7716. No local build or tests were run.Results
mainNot verified
The hosted Windows, relinker, ASan, macOS register-context and write-watch jobs were pending when I reviewed. The Linux product job was skipped. The author reports no Windows/macOS/title/console validation.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T21:51:10Z.
Review: APPROVED
Follow-up to my earlier COMMENT review. The head is unchanged at
8a7cd7d35a. Host-only; I didn't run anything on the console.windowsandrelinker (windows-latest, g++)lanes now pass. Under Wine the UCRT results couldn't be trusted, so this lane was what I was waiting on, and it decides it.82e99009f5:git merge-treeis clean,git diff --checkis clean, andcheck_conventionspasses. Main hasn't touched either changed file since the PR's base.pr_overlapover 1443 PRs: the only ones sharing files are #5021, #7386, #10324, #11332 and #11726, and all five already conflict with main.The stream-path sibling (
HostVfscanf, which feeds the guestfscanf/vfscanf) is still an unmeasured follow-up lead. It doesn't block this PR.AI-assisted: yes