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

Closed
renzipego-cpu wants to merge 1 commit from upstream-pr/3892 into main
renzipego-cpu commented 2026-10-11 18:55:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by renzipego-cpu on 2026-10-11T18:55:21Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4821492736 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3892). Originally posted by [renzipego-cpu](https://github.com/renzipego-cpu) on 2026-10-11T18:55:21Z. --- 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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [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
milescoviello commented 2026-10-11 18:56:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T18:56:27Z.


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 (21d1698c, identical patch), together with the Windows half of #3117, and its checks pass. Either way is fine by me; just pointing out the overlap.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112514958 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3892#issuecomment-6112514958). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-11T18:56:27Z. --- 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 (21d1698c, 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 commented 2026-10-11 19:01:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by renzipego-cpu on 2026-10-11T19:01:48Z.


ok thanks

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112564765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3892#issuecomment-6112564765). Originally posted by [renzipego-cpu](https://github.com/renzipego-cpu) on 2026-10-11T19:01:48Z. --- ok thanks
santhoshkumar-dev commented 2026-10-11 19:43:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by santhoshkumar-dev on 2026-10-11T19:43:42Z.


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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112976028 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3892#issuecomment-6112976028). Originally posted by [santhoshkumar-dev](https://github.com/santhoshkumar-dev) on 2026-10-11T19:43:42Z. --- > 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](https://github.com/boykopovar/AnyPS5/commit/21d1698c26b03cee44c6f8dcdcf6cc420c7c8984), 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 commented 2026-10-11 23:59:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:59:12Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115352994 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3892#issuecomment-6115352994). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T23:59:12Z. --- 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.

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!3892
No description provided.