fix(libc): report null gmtime_s and localtime_s arguments to the constraint handler #12593
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12593"
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:57:42Z.
What
gmtime_sandlocaltime_snow report a nulltimerorresultto the constraint handler, as titles'libc.prxdoes. The handler gets"gmtime_s: bad argument"or"localtime_s: bad argument",EINVALand a null pointer, and the function returns null. Onmainit returned null without calling the handler.gmtime,localtime,gmtime_randlocaltime_rare built on these two. They keep returning null for a null argument without calling the handler, exactly as onmain.The default constraint-handler prerequisite is fulfilled on current main
b11c7bf84f5d2f636ff60166cc3371bd071e24d5: #9935 was closed after its changes landed through #10270. Merging its final head into this main produces the unchanged main tree. Earlier test and title measurements retain their recorded source pins.Overlap: ntamas94's #10409 (36-byte
struct tm,tm_isdst = -1fromgmtime_s) also edits these two functions. It currently conflicts withmainon its own; the change here is the four-line null check at the top of each function.Tested
Current-main refresh — 2026-11-02. Published head
23fcc2d857f40e9c7f2b0cbc451c89d574bddb30includes pinned maina4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8. The time-conversion constraint implementation and null argument fixtures are retained with main’s Time.cpp updates and timelocal debt. Quiet null returns of ordinary gmtime/localtime and _r forms remain the documented host compatibility behavior, not a new title-library assertion.Rebuilt actual libc/Ampr and selected tests from the final input tree.
guest_crt,guest_time_conversion,guest_time_extras,guest_mktime,guest_strftime,guest_localeeach pass three consecutive runs: 18 runtime passes, zero skips, plus public_headers. Conventions and whitespace pass. Source/input manifests, exact dependencies, library/test hashes, logs/JUnit and head-leased push receipts are attached. The same pinned main passes 18 selected groups three times (54 runtime passes) plus headers. All 34 recursive dependency trees/31,551 tracked blobs verify with zero errors; QuickJS’s update=none test262 corpus is explicitly excluded because it is not a library build input.Linux-7.2.11-arch1-1-x86_64-with-glibc2.44, Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON. Focused Linux CPU qualification only. Older Windows/module/reference reports retain their original pins; no fresh Windows/macOS, SDK-module, console, title/GPU or speed claim. AI-assisted: yes (Codex).
Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/math-six-main-a4eca-linux-extra10321-20261102.tar.gz; SHA-256 525ccb31a5d3d0f5adced5fda58818d8432f06c0afa7290139adb60ae6664b54.
Earlier dated qualifications below retain their recorded source/platform pins.
Windows 11, WinLibs GCC 15.2.0 UCRT r7, Release,
main319621ba2e.gmtime_s: 50,000 random calls with times across the 64-bit range and null arguments. Calls with a null argument differ in 4,960 cases onmainand 0 with this PR.tm_isdst(titles -1,main0), which #10409 addresses;gmtime_sgets those dates wrong (it returns wrapped years even forINT64_MAX), which this build does not copy.localtime_s: the titles report"localtime_s: bad argument"for a nulltimer, a nullresultand both. Its non-null path needs a time-zone import the loader doesn't provide, so it isn't compared._sfunctions: the titles'gmtime,localtime,gmtime_randlocaltime_rdon't check for null at all. Each of the eight null cases (one for each single-argument function, three for each_rfunction) ends in an access violation on PPSA07923. Returning null without a handler call for these four is thereforemain's existing, safer behaviour, which this PR keeps, not a titles rule.guest_time_conversiongainsCheckNullArguments, which covers each null combination for both functions and a valid call with no handler call. With the previousTime.cppit fails (null argument did not report a bad argument).guest_time_conversion,guest_time_extras,guest_mktime,guest_strftime,guest_crtandguest_localepass 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:39:48Z.
Review: COMMENTED
I ran this on macOS x86_64 (Apple clang, ASan+UBSan,
-fno-sanitize-recover), at head704acff4af. It's a standalone build ofTime.cpp,TimeExtras.cpp,Environment.cppandMultibyte.cppwith the target's-include HostStandardStreams.hpp, plus a two-function shim:__error_nid_postfixreturns&errno, andset_constraint_handler_s_nid_postfixcallsSonySetConstraintHandlerS.guest_time_conversionandguest_time_extraspass at head (3/3 runs).main'sTime.cpp,guest_time_conversionfails withnull argument did not report a bad argument, as your body says.git merge-treeagainstmain319621ba2eis clean, and conventions pass.gmtime_s/localtime_s(tzset,mktime,timegm,SonyCtimeS) passes non-null pointers, so the new handler call can't fire from inside the library.Mutants. I ran 12 against the two tests. 5 are killed:
main'sTime.cpp,gmtime_sreporting only a nulltimer, a message of"gmtime_s",ERANGEforEINVAL, andresultpassed as the handler pointer. These 7 survive:gmtime_s, both null → silentnullptrwhich == 2repeatswhich == 0, as oneandonlydean notedlocaltime_s, both null → silentnullptrlibc_gmtime/libc_localtimewithout the newtimer == nullptrguardtimerto the non-_sfunctions with a recording handler installedgmtime_r/localtime_rguarding onlyresult(If
gmtime_rloses its guard completely,guest_time_extrascatches it, because its null-resultcall aborts in the default handler.)The body says
gmtime,localtime,gmtime_randlocaltime_r"keep returning null for a null argument without calling the handler". That is half of this PR, but no test pins it. Here is a test-only diff. It includes oneandonlydean's (null, null) fix, and it checks that the four non-_sentry points (pluslibc_gmtime/libc_localtime) return null for every null combination while the recording handler is installed, without calling it:With this diff all 12 mutants are killed, and head stays green (3/3 under ASan+UBSan).
One question about provenance. Your native comparison covers
gmtime_sandlocaltime_s. Did the scratch loader also call the titles'gmtime/localtime/gmtime_r/localtime_rwith a null argument and a recording handler installed? If it did, a line in Tested would back up the new assertions. If it didn't, the non-_sside ismain's behaviour kept unchanged, which is fine, but the body could say so.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T15:38:50Z.
Review: COMMENTED
First Linux run of this head (the thread has Windows and a standalone macOS build).
Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. Headb8ea6ed9ccmerged (--no-commit) onto currentmained1e0ed08f; the merge is clean.guest_time_conversion: passes 3/3.guest_time_*,guest_mktime,guest_strftime,guest_crtandguest_locale: 10/10 pass.public_headers: passes.Time.cppandTimeExtras.cppfrommainand this PR's test kept,guest_time_conversionaborts 3/3 atnull argument did not report a bad argument.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.