Repository navigation
fix(libc): check PATH_MAX before the segment in realpath, as realpath1 does - #24242
Conversation
…1 does FreeBSD's realpath1 appends the separator, and fails with ENAMETOOLONG when the resolved path has no room for it, before it looks at the next component. So an empty, "." or ".." component after a 1023-character resolved path fails. Since 5f6ae93 the port ran that check only for the other components and resolved those paths. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b7394815f7:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_realpath_testsbuilt cleanly. - CTest (
guest_realpath):1/1 Test #1311: guest_realpath ................... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libc/src/RealPath.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #1311: guest_realpath ...................Subprocess aborted***Exception: 1.17 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Checked RealPath.cpp:ResolveGuest length check: result.size() > 1 && result.size() + 1 >= PathMax correctly mirrors FreeBSD 11 realpath1 separator pre-check before consuming next token
- Verified error code semantics: NameTooLong (63, ENAMETOOLONG) returned on overflow, matching FreeBSD realpath1 and POSIX specs
- Checked edge cases where result is root ('/') or length 1, ensuring no false-positive trigger since result.size() > 1 guard is present
- Verified GuestRealpath.cpp test additions: assertions properly verify both successful resolution (hop1, hop1/) and boundary failure with errno 63 and preserved resolved prefix for //, /., /./, /.., /../sub, /x
- Checked memory safety, pointer validation, and AGENTS.md rules (no comments, conventional commits, clean diff)
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head b7394815f716eb4846471813eebdc3da8affd488 using the prepared diff and repo_read.py. No commands or tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and source review | passed | Changed behavior and tests inspected |
| Automated checks | not run | Author-reported results were not rerun |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author's reported Windows build and test results were not independently verified. No files were excluded by the manifest. Read both changed files in full: core/libs/prx/libc/src/RealPath.cpp and core/libs/tests/GuestRealpath.cpp.
To get this to a good state
Nothing is required.
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
|
Linux run (the Tested section lists Windows only). Setup: Fedora 44, kernel 7.3.4, GCC 16.2.1, glibc from F44, Release. Head Result: AI-assisted: yes |
What
realpathresolved a path that FreeBSD refuses withENAMETOOLONG: an empty,.or..component that follows a resolved path of 1023 characters.The debt entry says the function follows FreeBSD 11's
realpath.c. Inrealpath1the separator is appended, and its room checked, before the component is looked at:The port had the two in that order until #21264 (5f6ae93) moved the length check below the
continues, so that it only applied to the remaining components. This PR puts it back.With
hop1a link whose target resolves to a 1023-character pathD(the case the existing test builds):realpath1hop1,hop1/DDhop1//,hop1/.,hop1/./ENAMETOOLONG,resolvedholdsDDhop1/..ENAMETOOLONG,resolvedholdsDDhop1/../subENAMETOOLONG,resolvedholdsDDhop1/xENAMETOOLONGENAMETOOLONGThe FreeBSD column is not read off the source only: I compiled the body of
realpath1fromstable/11against a small simulated file system holding the same links and ran the eight paths.Tested
Windows 11 IoT Enterprise LTSC 2024 (10.0.26100), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON.core/libs/tests/GuestRealpath.cpp(guest_realpath, already registered, no CMake change): the five lines that expected a result forhop1//,hop1/.,hop1/./,hop1/..andhop1/../subnow expect a null result,errno63 and the 1023-character path left in the output buffer, as forhop1/x;hop1andhop1/are added and still resolve; the two path lengths the case relies on (1019 and 1023) are asserted.maine825fa1492,guest_realpathaborts.guest_realpathpasses, and so doguest_path_case,guest_path_drive_component,guest_path_name_length,guest_filesystemandguest_filesystem_error. I did not rebuild the rest of the libc suite.python tools/check_conventions.py --base origin/mainpasses.python tools/pr_overlap.py --names realpath: no open pull request.python tools/pr_overlap.py --branch fix/libc-realpath-path-max-before-segment: no overlap with open pull requests.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)