fix(libc): realpath resolves symbolic links like FreeBSD #11269
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11269"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-25T23:14:30Z.
What
realpathnever looked at symbolic links: on Windows it returned the link's own name (/dir/link -> /dir/link), succeeded for a dangling link, and could not tell a loop. FreeBSD 11.4'srealpath1lstats each component and, for a link, replaces the component with thereadlinktext, then keeps resolving. This change follows that loop:link/inner.txtthrough a directory link givessub/inner.txt), a chain of links resolves to the end, and..after a link is taken against the target;ENOENTand leaves the missing target path inresolved; a loop, or more than 33 links in one resolution (symlinks++ > MAXSYMLINKS), fails withELOOP;file-link/x,file-link/) fails withENOTDIR;PATH_MAX, fails withENAMETOOLONG, and an empty link text withENOENT, as in the source.A link whose target is absolute (a host path, which a guest
symlinkcannot create either) is not expanded: it keeps the previous behaviour, because there is no guest path to resolve it to, and no later component of that resolution is expanded either (the guest path still names the link, so a relative..in a link beneath it would otherwise resolve against the wrong directory; this is also whatmaindoes, soabs-link/../file-linkstays/file-link). Only Windows symbolic links (reparse tagIO_REPARSE_TAG_SYMLINK) are expanded; other reparse points are treated as before. On other hostsstd::filesystem::read_symlinkis used. Nothing else changes, including the backslash separators and thegetcwdstart.Known limits: the expansion works on the guest path, so a link made on the host whose text climbs with
..above a path alias root (or an alias whose host directory is itself a relative link) is resolved against the guest tree rather than the host one, and can fail withENOENTwheremainreturned the unexpanded name. Links created by the guest cannot do this, since the guestsymlinkrefuses..and absolute targets.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, Developer Mode on, onmainb90d009d9f(upstream has since moved on without touching this code).docs/dev/debt/libc.md: therealpathentry now says relative links are expanded and that absolute-target links, anything below them, junctions and host links that climb above a path alias root are not.guest_realpath: new checks next to the existing ones for a file link, a directory link (alone, with a child, with.., with a trailing/), a chain, a relative link containing.., a dangling link (ENOENTand the trouble path), a loop (ELOOP), a path below a file link (ENOTDIR), and a chain of 33 links (resolves) against 34 (ELOOP), and a directory link with an absolute target (its children, including a relative link, resolve as before). The block is skipped, without failing, when links cannot be created, and it now also compiles for other hosts, where the links are made withstd::filesystem::create_symlink(not run by me; an equivalent port of these checks was run on Linux by wachi35676 and passed with this change). Onmainthe test fails; with this change it passes, three runs out of three.pr_overlap_encoding,agc_host_import_cut_lifetimeandagc_driver_depth_plane_partial_store, which fail onmainin this environment too;agc_import_settle_initial_dcctimed out underctest -j 12and passes alone three times out of three.python tools/check_conventions.py --base upstream/main: passes.tools/pr_overlap.py: no overlap with open pull requests.read_symlinkbranch), a console, a title run.readlinkandreadlinkatwere probed as well (short buffer, non-linkEINVAL, null buffer) and the existing tests already cover them, so they are unchanged.Overlaps
None reported by
tools/pr_overlap.py.Checklist
main; no other open PR implements the same functionNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:26:02Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
eb1e38f442e7cf7e8753d5ff89b10dbec3ed0a56. The relative-link expansion and Windows regressions cover useful cases, and the hosted conventions, policy, relinker matrix and ASan checks now pass. One repository documentation gap remains:ReadGuestLink()explicitly throws for absolute symlink targets, butdocs/dev/debt/libc.mdis unchanged and still says symlinks are not expanded at all. That entry no longer describes the implementation or its remaining limitation. Please update it to distinguish supported relative links from unsupported absolute targets (and add a focused regression for the unsupported path, if that is the intended boundary), or implement absolute guest-target resolution. I could not run the changed code locally: the test additions are Windows-only, and this checkout has no configured build directory. Full product jobs are skipped by path policy.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:33:04Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
eb6040b530ff07a6a5a14f47d5879bd97125b7dd. The PR description now explains the absolute-target boundary, but the repositorydocs/dev/debt/libc.mdentry is unchanged and still says symlinks are never expanded. It no longer describes this implementation, which now resolves relative links and preserves the old behavior for absolute host targets. Please update that debt entry to reflect the supported relative-link behavior and the absolute-target limitation; the repository rules require known gaps to be recorded there. Hosted conventions/policy checks pass; cross-platform relinker and macOS checks are still running, full product jobs are skipped, and I could not run this Windows-only test change locally.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:40:37Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
481ae30a4c5d99ee355cf858f424d00bfdd443a3. The Windows tests now cover relative file/directory links, chains,.., dangling links, loops, and the 33/34-link boundary. Two issues remain before I can approve:docs/dev/debt/libc.mdis unchanged and still says host symlinks are followed for existence/type but never expanded. This implementation now expands relative links, so the entry no longer describesrealpathor its remaining limits. Please update it to state what relative and absolute targets do and the host-link boundary._WIN32, butReadGuestLinkhas a separatestd::filesystem::read_symlinkimplementation for Linux/macOS and the PR says those hosts were not tested. Please add focused coverage for that branch (at least relative resolution, a dangling link and a loop), or explain why those hosts are outside the supported behavior.The body documents the absolute-target and host-root limitations, but those notes do not replace the repository debt entry. The policy, conventions and product-build checks I can see do not exercise the changed libc behavior; the PR reports Windows tests only. I have not independently run the Windows suite.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T06:35:17Z.
Review: APPROVED
Re-reviewed exact head
4ccb760d12ecb78bdbe3e02b2eb0e8cf4438a4e7. The debt entry now describes the supported relative-link behavior and remaining absolute-target/host-link limits, and the added regression block now covers both Windows and POSIX symlink paths. The independent Windows and Linux focused runs reportguest_realpathpassing 3/3; the current hosted conventions, policy, relinker, register-context, write-watch and ASan checks pass. Product Linux/Windows jobs are skipped by path policy. I found no remaining blocking issue in the reviewed diff.