Skip to content

fix(libc): safely probe the locale name of setlocale - #20653

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

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

Conversation

@milescoviello

Copy link
Copy Markdown
Contributor

What

setlocale checked locale[0] and strcmp'd the name with "C" straight through the guest pointer, so a non-null name pointing at unmapped memory faulted the host.

It only accepts "" and "C" (and a null name as a query), so it only needs the first two bytes. Those are now read with CopyGuestString_nid_no_patch capped at 2, the same approach as #20644 for the _Locinfo constructor:

  • "" and "C" come back as themselves and return "C";
  • any longer name doesn't fit and returns null, as before;
  • an unreadable name returns null, like an unsupported name.

The null query and every category's results for readable names are unchanged.

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>
@oneandonlydean
oneandonlydean merged commit d7938b9 into boykopovar:main Nov 15, 2026
22 checks passed
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