Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/libs/prx/libkernel/File/src/Open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ static int StatNative(const std::filesystem::path& native, bool directory, FileS

int APS5_VABI sceKernelStat(const char* path, FileStat* sb) {
std::string copy;
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error);
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error);
path = copy.c_str();
if (copy.empty()) return SceErrorFromErrno(2);
std::filesystem::path native;
Expand All @@ -479,7 +479,7 @@ int StatInDirectory_nid_no_patch(int directory, const char* path, FileStat* sb,

int APS5_VABI sceKernelUnlink(const char* path) {
std::string copy;
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error);
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error);
path = copy.c_str();
if (copy.empty()) return SceErrorFromErrno(2);
if (const int dot = RenameDotError_nid_no_patch(path)) return SceKernelError(dot);
Expand Down
10 changes: 5 additions & 5 deletions core/libs/prx/libkernel/File/src/Stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ int APS5_VABI getdents_nid_postfix(int fd, char* buf, int nbytes) {
int APS5_VABI sceKernelMkdir(const char* path, uint16_t mode) {
(void)mode;
std::string copy;
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error);
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error);
path = copy.c_str();
if (copy.empty()) return SceErrorFromErrno(GUEST_ENOENT);
std::filesystem::path native;
Expand Down Expand Up @@ -1643,7 +1643,7 @@ int APS5_VABI sceKernelRename(const char* from, const char* to) {

int APS5_VABI sceKernelRmdir(const char* path) {
std::string copy;
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error);
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error);
path = copy.c_str();
if (copy.empty()) return SceErrorFromErrno(GUEST_ENOENT);
if (const int dot = RenameDotError_nid_no_patch(path)) return SceKernelError(dot);
Expand Down Expand Up @@ -1687,7 +1687,7 @@ extern "C" {

int APS5_VABI sceKernelChmod_nid_postfix(const char* path, std::uint16_t mode) {
std::string copy;
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error);
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error);
path = copy.c_str();
if (copy.empty()) return SceErrorFromErrno(GUEST_ENOENT);
std::filesystem::path native;
Expand Down Expand Up @@ -1727,7 +1727,7 @@ static bool CopyInTimes(const KernelTimeval*& times, KernelTimeval (&local)[2])
int APS5_VABI sceKernelTruncate_nid_postfix(const char* path, std::int64_t length) {
if (length < 0) return SceErrorFromErrno(GUEST_EINVAL);
std::string copy;
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error);
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error);
path = copy.c_str();
if (copy.empty()) return SceErrorFromErrno(GUEST_ENOENT);
std::filesystem::path native;
Expand Down Expand Up @@ -1765,7 +1765,7 @@ int APS5_VABI sceKernelUtimes_nid_postfix(const char* path, const KernelTimeval*
if (!CopyInTimes(times, local)) return SCE_KERNEL_ERROR_EFAULT;
if (InvalidTimes(times)) return SCE_KERNEL_ERROR_EINVAL;
std::string copy;
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error);
if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error);
path = copy.c_str();
if (copy.empty()) return SceErrorFromErrno(GUEST_ENOENT);
std::filesystem::path native;
Expand Down
16 changes: 16 additions & 0 deletions core/libs/tests/GuestPathNameLength.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "prx/libkernel/include/Api.hpp"
#include "prx/libkernel/File/include/File.hpp"
#include "prx/libkernel/KernelErrors.hpp"
#include "prx/libc/include/Api.hpp"
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstdint>
Expand All @@ -24,6 +26,18 @@ bool TooLong(const std::string& path) {
return Fails(stat_nid_postfix(path.c_str(), reinterpret_cast<FileStat*>(status)), ErrorNameTooLong);
}

void RequireSceTooLong(const std::string& path, const char* what) {
unsigned char status[256];
const char* name = path.c_str();
const int results[] = {sceKernelStat(name, reinterpret_cast<FileStat*>(status)), sceKernelUnlink(name), sceKernelMkdir(name, 0755), sceKernelRmdir(name), sceKernelChmod_nid_postfix(name, 0644), sceKernelTruncate_nid_postfix(name, 0), sceKernelUtimes_nid_postfix(name, nullptr)};
const char* calls[] = {"sceKernelStat", "sceKernelUnlink", "sceKernelMkdir", "sceKernelRmdir", "sceKernelChmod", "sceKernelTruncate", "sceKernelUtimes"};
for (int index = 0; index < 7; ++index) {
if (results[index] == SCE_KERNEL_ERROR_ENAMETOOLONG) continue;
std::fprintf(stderr, "%s: %s returned 0x%X\n", what, calls[index], static_cast<unsigned>(results[index]));
std::abort();
}
}

}

int main() {
Expand All @@ -49,9 +63,11 @@ int main() {
Require(!TooLong(block + block + block + name255), "a path of exactly 1023 bytes must not be too long");
#endif
Require(TooLong(block + block + block + block), "a path of exactly 1024 bytes must fail with ENAMETOOLONG (63)");
RequireSceTooLong(block + block + block + block, "the sce path calls must fail a path of exactly 1024 bytes with SCE_KERNEL_ERROR_ENAMETOOLONG");
Require(rmdir_nid_postfix("anyps5_name_length") == 0, "rmdir of the test directory failed");
Require(Fails(stat_nid_postfix((longName + "/x").c_str(), reinterpret_cast<FileStat*>(status)), ErrorNameTooLong), "stat of a long first component must fail with ENAMETOOLONG (63)");
Require(Fails(stat_nid_postfix(longPath.c_str(), reinterpret_cast<FileStat*>(status)), ErrorNameTooLong), "stat of a path of 1100 bytes must fail with ENAMETOOLONG (63)");
RequireSceTooLong(longPath, "the sce path calls must fail a path of 1100 bytes with SCE_KERNEL_ERROR_ENAMETOOLONG");
Require(Fails(access_nid_postfix(longName.c_str(), 0), ErrorNameTooLong), "access of a long name must fail with ENAMETOOLONG (63)");
Require(Fails(chflags_nid_postfix(longName.c_str(), 0), ErrorNameTooLong), "chflags of a long name must fail with ENAMETOOLONG (63)");
Require(Fails(unlink_nid_postfix(longName.c_str()), ErrorNameTooLong), "unlink of a long name must fail with ENAMETOOLONG (63)");
Expand Down
Loading