kernel: return ENOENT from unlink when the file does not exist (#5393)

posix_unlink never checked that the path exists. For a missing file it
opened the host path, the open failed, IOFile::Unlink returned early
because the file was not open, and the call still returned 0. On the
console unlink(2) fails with ENOENT, so sceKernelUnlink should return
0x80020002. Check the path with MntPoints::Exists first, as
posix_truncate already does.

Also check for a null path before calling strlen on it, and report
EFAULT like the other path functions in this file instead of crashing.
This commit is contained in:
Henrique Reis Neves authored and GitHub committed 2026-10-20 04:52:06 -07:00
1 parent 36f836f16d
commit ab94de0eb6
1 file changed
+9 -4
+9 -4
View File
@@ -1648,18 +1648,23 @@ s64 PS4_SYSV_ABI sceKernelPwritev(s32 fd, const OrbisKernelIovec* iov, s32 iovcn
}
s32 PS4_SYSV_ABI posix_unlink(const char* path) {
if (strlen(path) > 255) {
*__Error() = POSIX_ENAMETOOLONG;
if (path == nullptr) {
*__Error() = POSIX_EFAULT;
return -1;
}
if (path == nullptr) {
*__Error() = POSIX_EINVAL;
if (strlen(path) > 255) {
*__Error() = POSIX_ENAMETOOLONG;
return -1;
}
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
if (!mnt->Exists(path)) {
*__Error() = POSIX_ENOENT;
return -1;
}
bool ro = false;
const auto host_path = mnt->GetHostPath(path, &ro);
if (host_path.empty()) {