libc: rename checks the destination argument before the source, where FreeBSD looks up the source first; fix branch ready #8356

Closed
opened 2026-10-20 10:58:29 +00:00 by xXPBSXx · 0 comments
xXPBSXx commented 2026-10-20 10:58:29 +00:00 (Migrated from github.com)
Contributor

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


On Windows, rename, _rename and sceKernelRename reject a NULL, empty or .-ending destination before they look at the source. FreeBSD 11.4 resolves the source first (kern_renameat: namei(&fromnd) returns the source's error before the destination is looked at, namei(&tond) follows at :3232). So rename(missing, NULL) and rename(missing, ".") fail with ENOENT there, where we return EFAULT and EINVAL; rename(".", NULL) and rename(".", "") fail with EINVAL.

Cause. RenameGuestPath_nid_no_patch tests both arguments for NULL, empty and a dot component before it resolves either path, and sceKernelRename rejects a NULL destination itself.

Observed on main 01e5f8f199, Windows 10 (10.0.19045), WinLibs GCC 15.2.0 r7, Release: the added assertions in guest_filesystem abort on main (exit code 0xc0000409) and pass with the fix. I did not run the individual calls against main; the results above come from reading the source. I have not found a title that stops on this; it came out of reading the libkernel and libc file calls against the FreeBSD 11.4 sources.

Fix, ready to cherry-pick. xXPBSXx:fix/libc-rename-source-first (308848e1a6, one commit on main 7602dde042, three files, +25/-4). The source is checked first (NULL, empty, dot component); a bad destination is then reported only if the source exists, otherwise the source's ENOENT or ENOTDIR wins. Valid arguments and the existing destination errors behave as before.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5940455914 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8356). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T10:58:29Z. --- On Windows, `rename`, `_rename` and `sceKernelRename` reject a NULL, empty or `.`-ending destination before they look at the source. FreeBSD 11.4 resolves the source first ([`kern_renameat`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/vfs_syscalls.c#L3217-L3218): `namei(&fromnd)` returns the source's error before the destination is looked at, `namei(&tond)` follows at [:3232](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/vfs_syscalls.c#L3232)). So `rename(missing, NULL)` and `rename(missing, ".")` fail with `ENOENT` there, where we return `EFAULT` and `EINVAL`; `rename(".", NULL)` and `rename(".", "")` fail with `EINVAL`. **Cause.** [`RenameGuestPath_nid_no_patch`](https://github.com/boykopovar/AnyPS5/blob/01e5f8f199/core/libs/prx/libc/src/Rename.cpp#L97-L101) tests both arguments for NULL, empty and a dot component before it resolves either path, and [`sceKernelRename`](https://github.com/boykopovar/AnyPS5/blob/01e5f8f199/core/libs/prx/libkernel/File/src/Stdio.cpp#L1381-L1384) rejects a NULL destination itself. Observed on `main` 01e5f8f199, Windows 10 (10.0.19045), WinLibs GCC 15.2.0 r7, Release: the added assertions in `guest_filesystem` abort on `main` (exit code 0xc0000409) and pass with the fix. I did not run the individual calls against `main`; the results above come from reading the source. I have not found a title that stops on this; it came out of reading the libkernel and libc file calls against the FreeBSD 11.4 sources. **Fix, ready to cherry-pick.** [`xXPBSXx:fix/libc-rename-source-first`](https://github.com/boykopovar/AnyPS5/compare/main...xXPBSXx:AnyPS5:fix/libc-rename-source-first) (308848e1a6, one commit on `main` 7602dde042, three files, +25/-4). The source is checked first (NULL, empty, dot component); a bad destination is then reported only if the source exists, otherwise the source's `ENOENT` or `ENOTDIR` wins. Valid arguments and the existing destination errors behave as before. AI-assisted (Claude Code).
Sign in to join this conversation.
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#8356
No description provided.