fix(libc): end sscanf and vsscanf at a q length on Linux and macOS #11852
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11852"
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 ionut27001 on 2026-10-27T09:51:15Z.
What
On Linux and macOS,
sscanfandvsscanfpassed aqlength straight to the host libc, which reads it asll:sscanf("5", "%qd", &q)stored 5 and returned 1. On Windows the scan already ends at theqdirective with nothing stored (WindowsScanning.hpp), so the hosts differed.Evidence is our own payload probe on a PS5 (firmware 12.70,
sscanfresolved fromlibSceLibcInternal.sprx). It was not run in a title process. Case lines:%qdstored nothing and%qnwas not reached, so the scan ended at the firstqdirective. That probe did not have a plain narrow%qdcase without a preceding wide field.This change adds
LibcDetail::FindQuadScanDirective, which finds the first%qdirective the same way the Windows path does: it skips%%,*and width digits. On non-Windows hostssscanfandvsscanfcut the format before that directive, before choosing between the host libc and the in-process wide scanner. The format is copied only when aqis present.Only
sscanfandvsscanfchange.sscanfwas measured;vsscanfwas not, and followssscanfas it already did on the Windows path.HostVsscanfandHostVfscanfare unchanged, sofscanf,vfscanf,scanf,vscanfand the_sforms keep their previous behaviour. That is recorded in the debt entry.Overlaps: open scanf PRs #7386, #11724, #11726, #9340, #9087 and #9863 have no added lines that handle
q. #5303 mentions%qdfor printf only.Tested
The changed code in
sscanfandvsscanfis compiled only on Linux and macOS. It was not built or run here; nothing was run on Linux, macOS or with a title.Windows 11, WinLibs GCC 15.2.0:
guest_formattingandguest_wide_formattingpass twice. On Windows this runs the existing Windows scan path and the newFindQuadScanDirectiveheader, not the changed Linux/macOS code. The%qdcheck is no longer limited to Windows. It also checks that"%d %qd"on"7 5"returns 1 with only the first value stored through bothsscanfandvsscanf, that%qSreturns 0 with nothing stored, that%%qdis matched as literal text, and whereFindQuadScanDirectivestops.Formatting.cppreverted, the test still passes on Windows, so no Windows run shows the fix. Removing the existingqcut fromWindowsScanning.hppmakesguest_formattingfail, so the new checks catch a scan that does not stop atq.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 MarcZX10 on 2026-10-27T10:42:55Z.
Review: DISMISSED
I configured and built the exact head on Linux with the repository-pinned submodules;
guest_formattingandguest_wide_formattingpass. As a negative control, I restored onlyFormatting.cppfrom the PR base:guest_formattingthen fails at the new%qdassertion, and it passes again after restoring the PR file. This confirms the Linux regression test exercises the changed path.One behavior-scope issue remains. The console evidence is from
sscanfonly, and the PR explicitly recordsfscanfandsscanf_sas unmeasured. The shared host changes also affectfscanf/vfscanf/scanf/vscanfthroughHostVfscanf, and secure variants throughHostSscanf/HostFscanfcalled byScanGuest; these functions now all stop at%qon Linux/macOS. The repository rule requires unknown behavior to remain an explicit failure until it is measured, rather than assuming all entry points share the observed console behavior. Please either provide console evidence for the affected scan variants and record any remaining gaps, or keep the unmeasured variants on an explicit unsupported path until then. I could not run the macOS build/runtime test on this Linux host; the PR’s Windows test does not compile the changed non-Windows branch.