Repository navigation
fix(libc): return invalid argument error on null buffer in basename_r - #10074
voidlakhan wants to merge 1 commit into
Conversation
Set errno to EINVAL (22) and return nullptr when buffer is null in basename_r, following POSIX reentrant conventions and preventing host exception crashes on invalid guest input. Add regression test covering null buffer handling in GuestStrings and record technical debt.
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
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.
|
|
The flagged line collision in
|
|
@voidlakhan Could you provide a console measurement or relevant public ABI source establishing EINVAL for basename_r with a null output buffer? FreeBSD 11.4 basename.c:25–59 dereferences that buffer without a null/EINVAL branch, and generic POSIX conventions do not establish this BSD extension’s result. Otherwise, retain the existing fail-fast behaviour and remove the new return-code expectation. Please also remove the unsupported standard-POSIX and always-host-crash claims. |
|
@oneandonlydean Thanks for the pointer to FreeBSD 11.4 |
What
basename_rthrewstd::invalid_argumentacross the PRX ABI boundary when passed a null output buffer. Throwing C++ exceptions across guest PRX boundaries causes a host crash rather than reporting standard libc error status to the calling guest code.This change:
errnotoEINVAL(22) and returnsnullptrwhenbnameisnullptr, following standard POSIX reentrant conventions and sibling error handling patterns.GuestStrings.cppasserting thatbasename_r(path, nullptr)returnsnullptrwitherrno == 22.docs/dev/debt/libc.mddocumenting standard POSIXEINVALbehavior on null buffer inbasename_r.Tested
ninja -C build-full guest_string_testscompiled cleanly (0 warnings/errors).ctest --test-dir build-full -R guest_strings -V: passed (1/1 tests passed in 0.04s).python tools/check_conventions.py --base upstream/main: passed locally with 0 findings.git diff --check upstream/main..HEAD: clean (0 whitespace or format errors).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)