fix(libc): resolve the rename source before the destination argument #8358

Merged
xXPBSXx merged 2 commits from upstream-pr/8358 into main 2026-10-20 13:30:35 +00:00
xXPBSXx commented 2026-10-20 10:58:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T10:58:51Z.


What

rename, _rename and sceKernelRename checked the destination (NULL, empty, dot component) before they looked at the source. FreeBSD 11.4 kern_renameat (vfs_syscalls.c:3217) looks up the source first and returns its error before it touches the destination (:3232). The source is now checked first (NULL, empty, dot component, then existence and non-directory prefix); a NULL, empty or dot destination is reported only for a source that exists. sceKernelRename no longer rejects a NULL destination on its own.

Fixes #8356

Tested

Windows 10 (19045), WinLibs GCC 15.2.0 r7, Release, on main 7602dde042 + this commit (308848e1a6); the run without the change was made on main 01e5f8f199:

  • guest_filesystem: aborts with exit code 0xc0000409 without the changes to Rename.cpp and Stdio.cpp, passes with them, 3 of 3 runs.
  • guest_rename_dot, guest_kernel_rename and guest_posix_filesystem pass, 3 of 3 runs each.
  • python tools/check_conventions.py --base upstream/main and git diff --check pass.
  • Not tested: Linux, a console, a title run.

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source: none
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: #8356
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
    AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4934744810 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8358). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T10:58:51Z. --- ### What `rename`, `_rename` and `sceKernelRename` checked the destination (NULL, empty, dot component) before they looked at the source. FreeBSD 11.4 `kern_renameat` (vfs_syscalls.c:3217) looks up the source first and returns its error before it touches the destination (:3232). The source is now checked first (NULL, empty, dot component, then existence and non-directory prefix); a NULL, empty or dot destination is reported only for a source that exists. `sceKernelRename` no longer rejects a NULL destination on its own. Fixes #8356 ### Tested Windows 10 (19045), WinLibs GCC 15.2.0 r7, Release, on `main` 7602dde042 + this commit (308848e1a6); the run without the change was made on `main` 01e5f8f199: - `guest_filesystem`: aborts with exit code 0xc0000409 without the changes to `Rename.cpp` and `Stdio.cpp`, passes with them, 3 of 3 runs. - `guest_rename_dot`, `guest_kernel_rename` and `guest_posix_filesystem` pass, 3 of 3 runs each. - `python tools/check_conventions.py --base upstream/main` and `git diff --check` pass. - Not tested: Linux, a console, a title run. ### 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; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source: none - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: #8356 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-20 11:07:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T11:07:40Z.


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.

Pull request Shared files not compared
PR 5021 core/libs/prx/libc/src/Rename.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 6044 core/libs/tests/GuestFilesystem.cpp
core/libs/tests/GuestPosixScalarIo.cpp
PR 6879 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 6936 core/libs/prx/libkernel/File/src/Stdio.cpp
core/libs/tests/GuestPosixScalarIo.cpp
PR 6977 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7201 core/libs/prx/libc/src/Rename.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289478786 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8358#issuecomment-6289478786). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T11:07:40Z. --- <!-- pr-overlap --> 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. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/src/Rename.cpp`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestFilesystem.cpp`<br>`core/libs/tests/GuestPosixScalarIo.cpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `core/libs/prx/libkernel/File/src/Stdio.cpp`<br>`core/libs/tests/GuestPosixScalarIo.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/Rename.cpp`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` |
oneandonlydean commented 2026-10-20 11:44:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T11:44:42Z.


Thanks. The new order matches FreeBSD's kern_renameat: the source lookup comes first, and a NULL destination only fails inside the second namei. One existing test still expects the old order, so from reading the code (we haven't run it yet) it should now fail:

core/libs/tests/GuestPosixScalarIo.cpp:172:

Require(sceKernelRename("src", nullptr) == static_cast<std::int32_t>(0x8002000eu));

"src" is a relative path that doesn't exist in the test's working directory (ctest runs it in build/core/libs). With this change the missing source is reported first, so sceKernelRename returns 0x80020002 and guest_posix_scalar_io aborts on Linux and Windows. Could you update that line to expect ENOENT, or rename an existing file to nullptr if you want to keep the EFAULT case there?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6290091137 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8358#issuecomment-6290091137). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T11:44:42Z. --- Thanks. The new order matches FreeBSD's `kern_renameat`: the source lookup comes first, and a NULL destination only fails inside the second `namei`. One existing test still expects the old order, so from reading the code (we haven't run it yet) it should now fail: `core/libs/tests/GuestPosixScalarIo.cpp:172`: ```cpp Require(sceKernelRename("src", nullptr) == static_cast<std::int32_t>(0x8002000eu)); ``` `"src"` is a relative path that doesn't exist in the test's working directory (ctest runs it in `build/core/libs`). With this change the missing source is reported first, so `sceKernelRename` returns `0x80020002` and `guest_posix_scalar_io` aborts on Linux and Windows. Could you update that line to expect ENOENT, or rename an existing file to `nullptr` if you want to keep the EFAULT case there?
xXPBSXx commented 2026-10-20 12:31:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T12:31:21Z.


Thanks for catching this, @oneandonlydean, and sorry for the broken test. GuestPosixScalarIo.cpp:172 still expected EFAULT for sceKernelRename("src", nullptr), but src does not exist in that test, and with this change the source's error comes first, as in FreeBSD's kern_renameat, so it now returns ENOENT. I had built only the rename tests I knew of instead of searching the tests for every caller.

Pushed 0a0910c54d: the expectation on that line is now 0x80020002 (ENOENT); EFAULT for a NULL destination is still covered where the source exists (GuestFilesystem.cpp, GuestKernelRename.cpp).

I then found every test in core/libs/tests that calls rename, _rename or sceKernelRename, built them and ran each with ctest on Windows 10 (19045, WinLibs GCC 15.2.0 r7, Release): guest_posix_scalar_io, guest_kernel_sys, guest_kernel_sync, guest_kqueue, guest_path_name_length, guest_path_case, file_streams, guest_filesystem, guest_rename_dot and guest_kernel_rename all pass. I did not run Linux.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6290894011 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8358#issuecomment-6290894011). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T12:31:21Z. --- Thanks for catching this, @oneandonlydean, and sorry for the broken test. `GuestPosixScalarIo.cpp:172` still expected `EFAULT` for `sceKernelRename("src", nullptr)`, but `src` does not exist in that test, and with this change the source's error comes first, as in FreeBSD's `kern_renameat`, so it now returns `ENOENT`. I had built only the rename tests I knew of instead of searching the tests for every caller. Pushed `0a0910c54d`: the expectation on that line is now `0x80020002` (`ENOENT`); `EFAULT` for a NULL destination is still covered where the source exists (`GuestFilesystem.cpp`, `GuestKernelRename.cpp`). I then found every test in `core/libs/tests` that calls `rename`, `_rename` or `sceKernelRename`, built them and ran each with `ctest` on Windows 10 (19045, WinLibs GCC 15.2.0 r7, Release): `guest_posix_scalar_io`, `guest_kernel_sys`, `guest_kernel_sync`, `guest_kqueue`, `guest_path_name_length`, `guest_path_case`, `file_streams`, `guest_filesystem`, `guest_rename_dot` and `guest_kernel_rename` all pass. I did not run Linux. AI-assisted (Claude Code).
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!8358
No description provided.