fix(libc): preserve invalid strerror error precedence #2057

Closed
STUPIDCONTEM wants to merge 1 commit from upstream-pr/2057 into main
STUPIDCONTEM commented 2026-10-09 06:08:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by STUPIDCONTEM on 2026-10-09T06:08:04Z.


Evidence review (2026-10-09)

Game/title evidence has not been established. Validation below is host regression/build evidence only; it does not establish title compatibility. Older checked items and test results describe their stated revisions, not current merge readiness.

Game/title ID: none verified. No PS5 title execution is claimed.

What

strerror_r replaced EINVAL with ERANGE when the error number was unknown and the output buffer was also too short. Preserve EINVAL for unknown numbers, matching FreeBSD stable/11 strerror_r, which checks buffer truncation for valid error numbers only. Known errors still return ERANGE when their messages do not fit. Existing truncation, NUL termination, and errno preservation remain intact.

Tested

Windows 10 Pro 19045, WinLibs GCC 15.2.0 UCRT/posix/SEH r7, Ninja Release, BUILD_TESTING=ON, SPIRV-Tools disabled. Independent branch from f145139676a48306681d3a4d5fabf83938759daf.

  • New guest_strerror_r fails against unchanged upstream at short unknown buffer still returns EINVAL.
  • Regression covers known/unknown errors; negative, positive and extreme unknown numbers; ample, exact, short, one-byte and zero-byte buffers; NUL termination, adjacent sentinel bytes, and guest errno preservation.
  • Parent independently inspected the exact FreeBSD reference and reviewed the patch, then built and ran the regression in the full runtime.
  • Full default and explicit libs builds passed; full CTest: 489/489 passed, 31.78 s.
  • Committed-head conventions, whitespace and test-registration checks passed.

The separate regression leaves GuestErrors.cpp unchanged, avoiding the test-only change in #1712. #1729 uses strerror_r in syslog but does not change this implementation. Linux and PS5 hardware/titles were not run.

Checklist

  • Based on current main; no other open PR implements the same change (historical base; current readiness not asserted)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes — OpenAI Codex agents assisted with implementation; the parent agent independently reviewed and tested the final change.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796689890 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2057). Originally posted by [STUPIDCONTEM](https://github.com/STUPIDCONTEM) on 2026-10-09T06:08:04Z. --- ### Evidence review (2026-10-09) Game/title evidence has not been established. Validation below is host regression/build evidence only; it does not establish title compatibility. Older checked items and test results describe their stated revisions, not current merge readiness. Game/title ID: **none verified**. No PS5 title execution is claimed. ### What `strerror_r` replaced EINVAL with ERANGE when the error number was unknown and the output buffer was also too short. Preserve EINVAL for unknown numbers, matching [FreeBSD stable/11 strerror_r](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libc/string/strerror.c), which checks buffer truncation for valid error numbers only. Known errors still return ERANGE when their messages do not fit. Existing truncation, NUL termination, and errno preservation remain intact. ### Tested Windows 10 Pro 19045, WinLibs GCC 15.2.0 UCRT/posix/SEH r7, Ninja Release, BUILD_TESTING=ON, SPIRV-Tools disabled. Independent branch from `f145139676a48306681d3a4d5fabf83938759daf`. - New `guest_strerror_r` fails against unchanged upstream at `short unknown buffer still returns EINVAL`. - Regression covers known/unknown errors; negative, positive and extreme unknown numbers; ample, exact, short, one-byte and zero-byte buffers; NUL termination, adjacent sentinel bytes, and guest errno preservation. - Parent independently inspected the exact FreeBSD reference and reviewed the patch, then built and ran the regression in the full runtime. - Full default and explicit `libs` builds passed; full CTest: **489/489 passed**, 31.78 s. - Committed-head conventions, whitespace and test-registration checks passed. The separate regression leaves `GuestErrors.cpp` unchanged, avoiding the test-only change in #1712. #1729 uses strerror_r in syslog but does not change this implementation. Linux and PS5 hardware/titles were not run. ### Checklist - [ ] Based on current `main`; no other open PR implements the same change (historical base; current readiness not asserted) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes — OpenAI Codex agents assisted with implementation; the parent agent independently reviewed and tested the final change.
MarcZX10 commented 2026-10-09 06:09:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T06:09:17Z.

Review: APPROVED


Reviewed the complete diff and checked the cited FreeBSD stable/11 implementation: unknown error numbers keep EINVAL, while ERANGE is returned for truncation only on known errors. The new test covers precedence, truncation, NUL termination, sentinel safety, and guest errno. I built and ran the exact head on Linux with GCC 12; guest_strerror_r passed (1/1), and conventions/diff checks pass. Upstream has no check results for this fork head; the Windows full-suite evidence is reported in the PR description.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5466352108 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2057#pullrequestreview-5466352108). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T06:09:17Z. **Review:** APPROVED --- Reviewed the complete diff and checked the cited FreeBSD stable/11 implementation: unknown error numbers keep EINVAL, while ERANGE is returned for truncation only on known errors. The new test covers precedence, truncation, NUL termination, sentinel safety, and guest errno. I built and ran the exact head on Linux with GCC 12; guest_strerror_r passed (1/1), and conventions/diff checks pass. Upstream has no check results for this fork head; the Windows full-suite evidence is reported in the PR description.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2057
No description provided.