fix(libc): fail a rename of a path that ends in a dot component with EINVAL #8174
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8174"
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 xXPBSXx on 2026-10-20T01:18:26Z.
What
renameandsceKernelRenameresolved a path such asdir/.todirbefore renaming, sorename("dir/.", "other")moved the directorydir. FreeBSD 11.4's lookup (vfs_lookup.c) fails a last path component of.for theDELETEandRENAMEoperations withEINVAL(22), for the source and the destination alike:rename("dir/.", x),rename(x, "dir/."),rename(".", x)andrename(x, ".")all fail.A small header,
RenameDot.hpp, checks the guest string before it is resolved (resolving removes the.): a last component of.or..(also under trailing slashes,dir/./) fails withEINVALwhen its parent directory exists,ENOENTwhen the parent does not andENOTDIRwhen it is not a directory.rename(libc) andsceKernelRename(libkernel) call it for both arguments. A last component of..is refused the same way:vfs_lookup.cfailsISDOTDOTtogether withISLASTCNforDELETEandRENAMEwithEINVAL. The same lookup rule applies in FreeBSD tormdir("dir/."),unlink("dir/.")and the same calls with..; those are not changed here (the guest still resolves the dot component away and acts ondiror its parent) and stay open. Both open points are in the new TechnicalDebt entry for libc (docs/dev/debt/libc.md).Order of the checks: the header looks at both arguments before any host access, so
rename("missing", "dir/.")answersEINVALhere. FreeBSD'skern_renameatlooks the source up first (nameiwithDELETE) and the destination afterwards (nameiwithRENAME), so there the source error comes first:ENOENTfor a missing source (read inrelease/11.4.0). This difference and the backslash separator are in the TechnicalDebt entry for libc (next commit).No title evidence: found by calling
renamewith dot components in a failure-path probe. This is FreeBSD conformance; the effect on a title would be a directory moved by a call that should have failed.Overlap:
git merge-treeagainstupstream/mainis clean. This PR and #8164 each add one line todocs/dev/debt/libc.md; whichever lands second may need a rebase.pr_overlapwas not run.Fixes #8173
Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on upstream/main
340247a083+ these commits:guest_rename_dot:Exit code 0xc0000409without the changes toRename.cppandStdio.cpp, passes with them.guest_filesystem,guest_working_directoryandguest_directorypass.python tools/check_conventions.py --base upstream/main: passes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (docs/dev/debt/libc.md).mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T01:26:10Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libc/src/Rename.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/File/src/Stdio.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libc.mdcore/libs/prx/libkernel/File/src/Stdio.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libc/src/Rename.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T01:42:23Z.
Code review location:
core/libs/prx/libc/include/RenameDot.hpp; line 22Could this check propagate
statuswhen the filesystem query itself fails? With theerror_codeoverload,exists(resolved, status)returns false both for a missing path and for errors such as permission denied; this currently maps both toENOENT. Likewise, an error fromis_directoryis treated asENOTDIR. That can mask the parent lookup error instead of preserving it. Please checkstatusbefore classifying missing versus non-directory (for example, map a nonzero status withFilesystemError(status)).Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T03:58:16Z.
Thanks for the review. #8174 was merged before the change was ready; the fix is in 8217:
RenameDotErrornow reads the parent withstatus(), a missing path staysENOENT(ENOTDIRfornot_a_directory), any other status error is returned throughFilesystemError(status). I could not add a negative test: on Windows I have no reliable way to make the status of a parent fail with something other than 'not found'.