Skip to content

fix(libc): resolve ".." in guest paths against the directory before it - #3892

Closed
renzipego-cpu wants to merge 1 commit into
boykopovar:mainfrom
renzipego-cpu:fix/dotdot-path-resolution
Closed

renzipego-cpu wants to merge 1 commit into
boykopovar:mainfrom
renzipego-cpu:fix/dotdot-path-resolution

Conversation

@renzipego-cpu

Copy link
Copy Markdown

Carries the branch from #3117 (milescoviello:fix/dotdot-path-resolution@98a5a999), rebased onto current main and rebuilt here. Fixes #3117.

What

Resolve in libc/src/General.cpp normalizes the guest path with lexically_normal() before the host sees it, so the component before .. is never checked. On main (Linux), with dd/file a file and dd/victim a directory:

  • stat("dd/missing/../file") and open(...) succeed;
  • stat("dd/file/..") succeeds;
  • unlink("dd/missing/../file") deletes dd/file;
  • rmdir("dd/missing/../victim") deletes dd/victim.

FreeBSD's lookup() (sys/kern/vfs_lookup.c) resolves .. with VOP_LOOKUP in the directory reached so far, so these fail with ENOENT (missing component) or ENOTDIR (file component), and POSIX pathname resolution (XBD 4.13) says the same. With this change, .. is still collapsed when the path before it is an existing directory (aliases and case-insensitive matching keep behaving as before); otherwise the rest of the path reaches the host unchanged and reports the right error.

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, BUILD_TESTING=ON, full build including libs: guest_path_case and guest_realpath pass on the rebased branch. (guest_filesystem aborts on this machine without Windows Developer Mode for symlinks — same on clean main.) python tools/check_conventions.py --base upstream/main passes; no new test registration needed (the branch extends the existing GuestFilesystem.cpp cases).

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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

Guest paths were normalized lexically before they reached the host, so
"missing/../file" and "file/../x" dropped the component before "..":
stat and open succeeded on the file, unlink deleted it and rmdir removed
a directory, where FreeBSD's lookup() resolves ".." with VOP_LOOKUP in
the directory reached so far and fails with ENOENT for a missing
component and ENOTDIR for a file. POSIX path resolution (XBD 4.13) says
the same.

".." is still collapsed lexically when the path before it is an existing
directory, so case-insensitive matching and aliases behave as before.
When it is not, the rest of the path is passed to the host unchanged and
the host resolves it. Linux then reports ENOENT or ENOTDIR as FreeBSD
does; Windows collapses ".." itself, so its results are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XYhZu5HokHMo9mfi8QU83m
@milescoviello

Copy link
Copy Markdown
Contributor

Thanks for carrying it, @renzipego-cpu. A heads-up so it isn't reviewed twice: #3485 (@santhoshkumar-dev) already carries this same commit as its first one (21d1698, identical patch), together with the Windows half of #3117, and its checks pass. Either way is fine by me; just pointing out the overlap.

@renzipego-cpu

Copy link
Copy Markdown
Author

ok thanks

@santhoshkumar-dev

Copy link
Copy Markdown
Contributor

Thanks for carrying it, @renzipego-cpu. A heads-up so it isn't reviewed twice: #3485 (@santhoshkumar-dev) already carries this same commit as its first one (21d1698, identical patch), together with the Windows half of #3117, and its checks pass. Either way is fine by me; just pointing out the overlap.

+1

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: #3485 is merged and has this same commit as its first one, together with the Windows half of #3117.

You're welcome to reopen this if you think it was closed by mistake or the situation changes.

@renzipego-cpu
renzipego-cpu deleted the fix/dotdot-path-resolution branch October 12, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libc: guest paths resolve ".." lexically, so stat/open/unlink/rmdir act on "missing/../file" instead of failing; fix branch ready

4 participants