fix(libc): fail a rename of a path that ends in a dot component with EINVAL #5008
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5008"
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-13T08:01:39Z.
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-treeand the overlap bot againstmainb4d76ba60): the bot lists #4681 and #5009 (docs/dev/debt/libc.mdL57) and #5091 and #5144 (core/libs/prx/libkernel/CMakeLists.txtL270); this PR's TechnicalDebt entry now follows therealpathentry and its test registration sits beforeguest_fstatfs, away from those lines, and the merge is clean. #4938 changes neighbouring code inRename.cpp,Stdio.cppandFilesystemError.hpp; this PR leavesFilesystemError.hppalone and adds its own header. #4532 is merged.FinalPathComponentIsDot_nid_no_patchinGeneral.cpp(used byremoveand the stat calls) already finds a final.for/and\; this header does not reuse it because it also has to refuse..and to tell a missing parent (ENOENT) and a parent that is not a directory (ENOTDIR) fromEINVAL, and it treats/and\the same way. #5265 (new tests registered in the same part ofcore/libs/prx/libkernel/CMakeLists.txt) conflicts with this PR in that file (git merge-treeof the two heads, re-checked; #5325 and #5326 are closed); whichever lands second rebases the test registration. #5377 (runsceKernelRenamethrough the checksrenameuses) rewrites the body ofsceKernelRenameinStdio.cppinto one call toRenameGuestPath_nid_no_patch, the function in which this PR also refuses.and..; the two conflict in the lines ofsceKernelRename(git merge-treeof the two heads, re-checked; each is clean againstmain30f961266). Taking #5377's version ofsceKernelRenamekeeps this PR's behaviour, because the check inRenameGuestPath_nid_no_patchthen coverssceKernelRenameas well, andguest_rename_dotstill tests that path; whichever lands second rebases.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, first run, in a combined build on
mainb4d76ba60(rebased afterwards; the re-run with the current head is the bullet "Re-run on 14 October 2026" below):guest_rename_dot(new) passes:renamefromdir/.,dir/./,dir/..anddir/../, todir/.anddir/.., of.and..and onto.fail withEINVAL, a missing parent givesENOENT,sceKernelRenamereturnsEINVALfordir/.,dir/..and a destination ofdir/.,dir\.anddir\..are refused too (the guest resolver turns a backslash into a separator), nothing is moved by the failed calls, and an ordinaryrename/sceKernelRenamestill works.rename from dir/. must fail with EINVAL (22) (errno 2)).rename from dir\. must fail with EINVAL (22), the guest resolver turns the backslash into a separator (errno 2)).guest_filesystem,guest_kernel_rename,guest_file_vector,guest_directory*and the path tests pass.python tools/check_conventions.py --base upstream/mainpasses.-j4), the head5220be761(a0ad44f13plus a commit that only changesdocs/dev/debt/libc.md) merged ontomaind1670009f:guest_rename_dotpasses (0.11 s, ctest); withRename.cppandStdio.cpptaken back tomainand the new test kept it fails (rename from dir/. must fail with EINVAL (22) (errno 2), exit code0xc0000409). Group run with the code heada0ad44f13on the samemain, the targets built as well: onmainaloneguest_filesystem,guest_file_vector,guest_memory,guest_kernel_sys,guest_signalsandguest_directory_bufferpass (6 of 6); with the head and its test 7 of 7 pass, 0 failed. This replaces the earlier combined-build figures. Not run: the socket tests, Linux, a console, a title.Checklist
main; no other open PR implements the same functions (overlap described above)NotImplemented_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-13T16:34:36Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/CMakeLists.txtL1250core/libs/prx/libkernel/File/src/Stdio.cppL1195-1212Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:34:33Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed