Repository navigation
fix(libc): safely probe the time and buffer of strftime - #20645
Merged
oneandonlydean merged 1 commit intoNov 15, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
12 tasks done
oneandonlydean
pushed a commit
that referenced
this pull request
Nov 15, 2026
wcsftime formatted straight into the guest buffer and read the time through the guest pointer, so an unwritable buffer or an unreadable time faulted the host process. It now copies the time in, formats into a host buffer of at most 1 << 20 units and writes the units the direct writes covered with one GuestCopyOut, as #20645 did for strftime. An unwritable buffer returns 0 with errno kept, and an unreadable time throws.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
strftime(throughlibc_strftime) dereferencedtimeptrstraight through the guest pointer, andformatGuestTimememcpy'd each converted piece and the terminator straight into the guest buffer. An unreadable time or an unwritable buffer faulted the host.GuestTmwithGuestCopyIn_nid_no_patch.GuestCopyOut_nid_no_patch. The copy covers exactly the bytes the direct writes covered: the pieces that fit and, when the result fits, the terminator. The partial writes on overflow thatGuestStrftimepins are kept.strftime's failure result.std::invalid_argumentwcsftimethrows for a null time.The conversions, the return values and the time-zone handling are unchanged. The format string is still read in place.
The debt entry goes in a fragment under
docs/dev/debt/changes/and records this as unmeasured.Tested
Linux (Ubuntu 26.04.1), GCC 15.2, Release.
guest_strftime:strftimeinto an unmapped buffer (0x10) returns 0, and with an unmapped time it throwsstd::invalid_argument. The existing conversion table, week numbers, exact-fit, no-room-for-terminator, partial-piece and composite-conversion cases still pass.guest_time_conversionandguest_wide_formattingstill pass.Time.cppfrommainand this test,guest_strftimesegfaults.git merge-treeagainst the open PRs that touchlibc/src/Time.cpp(fix(libc): leave daylight saving undetermined in gmtime_s's result #19646, fix(libc): write a 36-byte struct tm as the console does #10409, feat(libc): add the std::__sce_v2 thread start, timed wait, clock and processor count calls #9447): no new conflicts.tools/check_conventions.pypasses on the branch and this body;tools/debt_fold.py --checkpasses with the fragment applied tomain.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)