fix(libc): report strerror_s violations as titles' libc.prx does #12589
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12589"
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-28T21:45:41Z.
What
strerror_snow reports its runtime-constraint violations the way thelibc.prxthat titles ship does. Measured natively on PPSA07923 and PPSA05916:main"strerror_s: bad argument""strerror_s"SIZE_MAX >> 3(2^61 and above is a violation)SIZE_MAX >> 1(from 2^61 up the message was written)Unchanged, and already matching the titles: a null destination or a capacity of 0 is a violation, the destination is left untouched, and the error is
EINVAL. A short buffer is still truncated with"..."and returns 0. The debt entry said these violation details were "not measured"; it now states the measured rule.strerror_salready called the handler onmain, so unlike #12574 and #12581 this does not wait for #9935.Merge notes:
"strerror_s\nstrerror_s\n"tostderr. Whichever lands second must change that expected text to"strerror_s: bad argument\nstrerror_s: bad argument\n". With that change, a local merge with #9935 (7aa063d91c) passesguest_safe_errors,guest_crtandguest_bounds_checking3/3.strerrornames),docs/dev/debt/libc.mdconflicts on neighbouring lines. The resolution is #12527's file with this PR's change to thestrerror_s and strerrorlen_sentry.Tested
Windows 11, WinLibs GCC 15.2.0 UCRT r7, Release,
main319621ba2e.Native comparison: a scratch loader calls the titles'
strerror_s,strerrorlen_s,strnlen_sandwcsnlen_sby NID next to this build's, with the same recording handler on both sides. For each it makes 20,000 random calls:2^61 - 1,2^61andSIZE_MAX;Each call compares the result, the handler's calls, error, pointer and message, and the buffer bytes.
mainstrerror_sviolationsstrerror_ssuccessful calls (extended names 108, 152, 1074)strerrorlen_s(same names)strnlen_s,wcsnlen_sBoth titles give the same results.
Regression:
guest_safe_errorsnow expects the titles' message, a null pointer, and rejection from(SIZE_MAX >> 3) + 1. With the previousWideConversion.cppit fails (constraint callback message and ABI).Test set:
guest_safe_errors,guest_crt,guest_bounds_checkingandguest_errorspass 3/3. Conventions pass.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-28T22:19:54Z.
Review: COMMENTED
I checked this on macOS 26 (x86_64 under Rosetta, Apple clang, ASan+UBSan). I built
WideConversion.cpp,Errors.cppandGuestSafeErrors.cppby themselves at head2fc5a44966, with a three-symbol shim (_Stderr_nid_postfixon hoststderr,__error, and an abortingwcrtomb).safe error message checks passed, and the sanitizers report nothing.main'sWideConversion.cppwith this PR's test: fails atconstraint callback message and ABI, which matches the Tested section.Mutants of
WideConversion.cpp, run against this PR's test:>> 3→>> 1(the old value)nullptr→ non-null"strerror_s"capacity == 0check dropped>> 3→>> 4capacity >→capacity >=SonyDefaultConstraintHandlerignores the message and aborts onmain(it only becomes visible with #9935)The test rejects
(SIZE_MAX >> 3) + 1but never accepts anything at or below the limit. A tighter limit therefore still passes, even though it contradicts the measured rule ("2^61 and above is a violation", so 2^61 − 1 is valid). This test-only diff covers the largest valid capacity (the copy stops at the message's terminator, so nothing past the 128-byte buffer is touched). It kills both survivors, and head stays green:With it,
>> 4and>=both fail atlargest valid capacity.Other checks:
check_conventionsagainst319621ba2epasses.git merge-treeagainst currentmainis clean.strerror_sare #9935, #10270 and #12527, which the merge notes already cover.AI-assisted: yes