Skip to content

fix(libc): safely probe the time and buffer of strftime - #20645

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/libc-probe-strftime
Nov 15, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/libc-probe-strftime

Conversation

@milescoviello

Copy link
Copy Markdown
Contributor

What

strftime (through libc_strftime) dereferenced timeptr straight through the guest pointer, and formatGuestTime memcpy'd each converted piece and the terminator straight into the guest buffer. An unreadable time or an unwritable buffer faulted the host.

  • The time is now copied into a local GuestTm with GuestCopyIn_nid_no_patch.
  • The text is formatted into a host buffer of the same size, capped at 1 MiB and not zero-filled, then written with one 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 that GuestStrftime pins are kept.
  • An unwritable buffer returns 0, strftime's failure result.
  • A null or unreadable time throws the std::invalid_argument wcsftime throws 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.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 9447 core/libs/prx/libc/src/Time.cpp
PR 10409 core/libs/prx/libc/src/Time.cpp
core/libs/tests/GuestStrftime.cpp

@oneandonlydean
oneandonlydean merged commit 31ff08e into boykopovar:main Nov 15, 2026
22 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants