fix(libc): reject memset_s violations as titles' libc.prx does #12594
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12594"
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-28T22:03:35Z.
Current refresh: head
11301c06e83d570b526baa57644580e4751de731includes main151a2cb6e274; scoped Linux CPU tests12/12, main24/24, public headers and regression controls pass. Current evidence is in the refresh comment; earlier platform reports retain their original pins.What
memset_snow accepts and rejects calls the way thelibc.prxthat titles ship does. Measured natively on PPSA07923 and PPSA05916, both of which agree:destis not null,destsz <= SIZE_MAX >> 3, andcount <= destsz. A0/0call on a validdestsucceeds.ERANGE(34), writes nothing, and calls the constraint handler with"memset_s: bad destination argument",ERANGEand a null pointer. That includes a nulldestwithdestsz = count = 0.On
mainit returnedEINVAL(22) without calling the handler, usedSIZE_MAX >> 1as the limit, and filleddestszbytes whencountwas larger.The old checks in
guest_stringsassertedmain's behaviour, which the titles contradict, so they move toguest_bounds_checkingasCheckMemset, which installs a recording handler.Fulfilled dependency: #9935 reached main through merged #10270, so the default constraint handler now writes and returns. orezraey’s request to keep this memset_s change separate from #10270’s copy functions is retained.
Fulfilled #10270 merge note (historical qualification):
core/libs/tests/GuestStrings.cppconflicts textually, because #10270's hunk at line 130 sits next to the removedmemset_slines. The resolution is #10270's merged file with those seven lines removed (sixRequire(memset_s_nid_postfix(...))lines and thesentineldeclaration). Merged that way onmain319621ba2ewith #102700bc7597aed:guest_bounds_checking,guest_strings,guest_safe_errors,guest_crtandguest_wide_stringspass 3/3;Tested
Current-main integration — 2026-11-04. Head
a2f6e23c8731896479fee84eccfa75396d6050c8includes mainb11c7bf84f5d2f636ff60166cc3371bd071e24d5and preserves previous public commits and attribution/licence notices. Retains the measured memset_s violation behavior and write-preservation fixtures while preserving main’s updated copy-function size bounds and returning default handler.Linux x86-64, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON: rebuilt actual libc/Ampr and selected executables.
guest_bounds_checking,guest_strings,guest_safe_errors,guest_crteach pass 3/3 (12 runtime passes, zero skips);public_headers, conventions and whitespace checks pass. Pinned main passes all 17 selected baseline groups 3/3 (51 passes) plus headers. Before/after dependency checks agree: 34 recursive trees and 31,551 tracked blobs, zero errors; the update=none QuickJS test262 corpus is explicitly excluded from these library inputs.Source/parent/gitlink proofs, library/test hashes, raw logs/JUnit and head-leased push receipts: qualification archive, SHA-256
7c347f620951ad6f39068740750949212c6412815da094a46a96eca1d15c8bbf(download verified). Older platform, stress, negative-control and reference reports retain their original pins; no new Windows/macOS, full-suite, SDK-module, console, title/GPU or performance claim. AI-assisted: yes (Codex).Earlier dated qualifications below retain their original source/platform pins.
Windows 11, WinLibs GCC 15.2.0 UCRT r7, Release,
main319621ba2e.Native comparison: a scratch loader calls the titles'
memset_sby NID next to this build's, with the same recording handler on both sides. It makes 20,000 random calls:SIZE_MAX >> 1and one above it;Each call compares the return value, whether the handler ran and with which error, and the destination bytes.
main: 11,242 of 20,000 differ, on both titles.SIZE_MAX), which also gave the message and the null pointer.CheckMemsetchecks 10 of those cases against this build.Regression: with the previous
Strings.cpp, the newCheckMemsetfails (memset_s accepted a violation).Test set:
guest_bounds_checking,guest_strings,guest_safe_errors,guest_crtandguest_wide_stringspass 3/3. Conventions pass.Independent Windows evidence from bunbeans2-arch: Windows 11 Pro, MSYS2 UCRT64 GCC 16.1.0, Release; head
37d0c191b5a04732daaca697ca5678ac9c670aafintegrated with main98ddd9c179.guest_bounds_checkingandguest_strings: change passed 5/5; reverting only production changes while retaining the regression tests failed 5/5 atmemset_s accepted a violation; plain main passed 3/3. This is the reporter's execution, not a new local Windows run.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:46:44Z.
Review: APPROVED
I ran this on macOS, which the body doesn't list (head
37d0c191b5, based onmain319621ba2e).Standalone ASan+UBSan build (macOS 26, Apple clang,
-arch x86_64): the PR'sStrings.cppandWideConversion.cpp(forset_constraint_handler_s), linked toCheckMemsetand the recording handler taken verbatim fromGuestBoundsChecking.cpp. I added three abort-only symbols for unrelatedStrings.cppimports; none of them is called.main'sStrings.cppwith the new test: fails withmemset_s accepted a violation, as the body says.Mutants of
memset_s_nid_postfix: the test kills all 16.>> 2, to>> 4, or applied tocountinstead ofdestsz.count > destszchanged to>=.destas its pointer, given error 22, or given the messagebad argument.destszbytes, orcount - 1bytes.destszbytes on a violation.Other checks:
memset_s_nid_postfixexists outside the export, so the stricter checks can't change another libc path.GuestStrings.cppandGuestBoundsChecking.cppcompile without new warnings (-Wall -Wextra).check_conventionspasses.git merge-treeagainstmainis clean.pr_overlaplists only the shareddocs/dev/debt/libc.md, plus #5021 and #11892 inStrings.cpp. #11892 merges cleanly with this PR. #5021 already conflicts withmainitself.LGTM once #9935 lands, as stated.