fix(filesystem): reject final dot removal paths #3436

Merged
MarcZX10 merged 1 commit from upstream-pr/3436 into main 2026-10-11 11:42:56 +00:00
MarcZX10 commented 2026-10-11 10:31:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T10:31:45Z.


What

On current main, guest path resolution lexically normalizes the final . component away. As a result, rmdir("dir/."), sceKernelRmdir("dir/.") and remove("dir/.") can remove the directory. POSIX/FreeBSD requires these calls to fail with EINVAL.

This checks the original final path component before removal. Missing paths still report ENOENT, and a regular file used as the parent still reports ENOTDIR. The regression test covers all three APIs, a trailing separator after ., and those existing error cases.

Tested

Linux, GCC 12.2, Release build. guest_filesystem fails on unmodified main at the new rmdir("dir/.") assertion (returns ENOTDIR instead of EINVAL) and passes with this change. tools/check_conventions.py --base upstream/main and git diff --check pass.

No PS5 title or homebrew test was run. Windows was not tested.

Checklist

  • Based on current main (99c1c263); no other open PR implements these 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 files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

Fixes #3116

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818412989 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3436). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T10:31:45Z. --- ### What On current `main`, guest path resolution lexically normalizes the final `.` component away. As a result, `rmdir("dir/.")`, `sceKernelRmdir("dir/.")` and `remove("dir/.")` can remove the directory. POSIX/FreeBSD requires these calls to fail with `EINVAL`. This checks the original final path component before removal. Missing paths still report `ENOENT`, and a regular file used as the parent still reports `ENOTDIR`. The regression test covers all three APIs, a trailing separator after `.`, and those existing error cases. ### Tested Linux, GCC 12.2, Release build. `guest_filesystem` fails on unmodified `main` at the new `rmdir("dir/.")` assertion (returns `ENOTDIR` instead of `EINVAL`) and passes with this change. `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. No PS5 title or homebrew test was run. Windows was not tested. ### Checklist - [x] Based on current `main` (99c1c263); no other open PR implements these functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes Fixes #3116
milescoviello commented 2026-10-11 10:33:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-11T10:33:39Z.


Thanks for picking up #3116, @MarcZX100. This builds on my branch fix/rmdir-dot-component (9aaf6240, rebased onto main this morning and rechecked on Windows by @Silverash-i8 in #3116): the same FinalPathComponentIsDot_nid_no_patch helper and the same check in sceKernelRmdir. Your remove handling is better than mine, though. It also gives ENOTDIR for file/., where my branch would still remove the file, and the test covers more.

Would you mind adding Co-authored-by: milescoviello <[email protected]> to the commit? Thanks either way.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108117018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3436#issuecomment-6108117018). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-11T10:33:39Z. --- Thanks for picking up #3116, @MarcZX100. This builds on my branch [`fix/rmdir-dot-component`](https://github.com/milescoviello/AnyPS5/tree/fix/rmdir-dot-component) (`9aaf6240`, rebased onto `main` this morning and rechecked on Windows by @Silverash-i8 in #3116): the same `FinalPathComponentIsDot_nid_no_patch` helper and the same check in `sceKernelRmdir`. Your `remove` handling is better than mine, though. It also gives `ENOTDIR` for `file/.`, where my branch would still remove the file, and the test covers more. Would you mind adding `Co-authored-by: milescoviello <[email protected]>` to the commit? Thanks either way.
MarcZX10 commented 2026-10-11 10:36:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T10:36:20Z.


Thanks for linking your branch and for the Windows validation. I added the requested Co-authored-by: milescoviello <[email protected]> trailer to the updated commit b37ab31b1.

The PR keeps the broader remove error handling and regression cases for missing paths and file/.; your helper and the final-dot behavior are credited in the commit. The updated head will get a fresh CI run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108137062 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3436#issuecomment-6108137062). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T10:36:20Z. --- Thanks for linking your branch and for the Windows validation. I added the requested `Co-authored-by: milescoviello <[email protected]>` trailer to the updated commit [`b37ab31b1`](https://github.com/MarcZX100/AnyPS5/commit/b37ab31b1cabe6bea07407072ae5927c04b3c1a3). The PR keeps the broader `remove` error handling and regression cases for missing paths and `file/.`; your helper and the final-dot behavior are credited in the commit. The updated head will get a fresh CI run.
adriadam10 commented 2026-10-11 11:42:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:42:53Z.


Checked on Linux (GCC, Release) with the PR merged onto current main: guest_filesystem passes, and fails with the non-test changes reverted. rmdir, sceKernelRmdir and remove return EINVAL for a final . (also with a trailing separator), after the ENOENT/ENOTDIR checks, matching FreeBSD kern_rmdirat. Co-author credit is in place; merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108656097 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3436#issuecomment-6108656097). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T11:42:53Z. --- Checked on Linux (GCC, Release) with the PR merged onto current `main`: `guest_filesystem` passes, and fails with the non-test changes reverted. `rmdir`, `sceKernelRmdir` and `remove` return `EINVAL` for a final `.` (also with a trailing separator), after the `ENOENT`/`ENOTDIR` checks, matching FreeBSD `kern_rmdirat`. Co-author credit is in place; merging once CI is green.
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!3436
No description provided.