Skip to content

fix(libc): keep EINVAL from strerror_r for an unknown error with a short buffer - #3130

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
fma-rc:fix/strerror-r-unknown-short
Oct 11, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
fma-rc:fix/strerror-r-unknown-short

Conversation

@fma-rc

@fma-rc fma-rc commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

What

strerror_r with an unknown error number and a buffer too small for the "Unknown error: N" text returned ERANGE (34). FreeBSD 11 returns EINVAL (22) for an unknown number whatever the buffer size: in lib/libc/string/strerror.c (releng/11.4) the errnum < 0 || errnum >= sys_nerr branch sets retval = EINVAL and only the known-number branch can set ERANGE. The text is still written truncated, as before.

One line in Errors.cpp, two assertions in guest_errors. #2057 made the same change and was closed by its author before review; this is a fresh patch on current main.

Tested

Arch Linux, GCC 16.2.1, Release, main d2f43cb. guest_errors with only the new assertions aborts; with the fix it passes 5 of 5. No GPU involved. python3 tools/check_conventions.py --base origin/main passes. Not tested on Windows.

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • AI-assisted: yes

@github-actions github-actions Bot added the intake paused Closed while PR intake is limited to authors with at least 10 PRs merged into main label Oct 10, 2026
@github-actions

Copy link
Copy Markdown

Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

@github-actions github-actions Bot closed this Oct 10, 2026
@oneandonlydean oneandonlydean removed the intake paused Closed while PR intake is limited to authors with at least 10 PRs merged into main label Oct 11, 2026
@github-actions github-actions Bot added the libc label Oct 11, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked against FreeBSD releng/11.4 strerror.c (EINVAL for unknown numbers, ERANGE only in the known-number branch); guest_errors passes and fails without the change on a Linux build. Merging.

@adriadam10
adriadam10 merged commit 097a628 into boykopovar:main Oct 11, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants