diff --git a/core/libs/prx/libkernel/File/src/Open.cpp b/core/libs/prx/libkernel/File/src/Open.cpp index 8811f3e4b..58c7f0046 100644 --- a/core/libs/prx/libkernel/File/src/Open.cpp +++ b/core/libs/prx/libkernel/File/src/Open.cpp @@ -294,15 +294,13 @@ int APS5_VABI sceKernelStat(const char* path, FileStat* sb) { if (path == nullptr) { throw std::invalid_argument(std::string(__func__) + ": path is null"); } - if (sb == nullptr) { - throw std::invalid_argument(std::string(__func__) + ": sb is null"); - } if (*path == '\0') return SceErrorFromErrno(2); std::filesystem::path native; if (const int error = ResolvePathError_nid_no_patch(path, native)) return SceKernelError(error); native = File::PathOrRelinkedModule(native); std::error_code error; constexpr int GuestEnotdir = 20; + constexpr int GuestEfault = 14; const auto status = std::filesystem::status(native, error); if (error == std::errc::not_a_directory) return SceErrorFromErrno(GuestEnotdir); if (!std::filesystem::exists(status)) { @@ -310,6 +308,7 @@ int APS5_VABI sceKernelStat(const char* path, FileStat* sb) { } const std::string_view guestPath(path); if (!guestPath.empty() && guestPath.back() == '/' && !std::filesystem::is_directory(status)) return SceErrorFromErrno(GuestEnotdir); + if (sb == nullptr) return SceErrorFromErrno(GuestEfault); File::FillFileStat(native, sb); return 0; } diff --git a/core/libs/tests/GuestFilesystem.cpp b/core/libs/tests/GuestFilesystem.cpp index 188f1595f..9f885695c 100644 --- a/core/libs/tests/GuestFilesystem.cpp +++ b/core/libs/tests/GuestFilesystem.cpp @@ -220,6 +220,8 @@ int main() { Require(chmod_nid_postfix("", 0600) == -1 && *__error_nid_postfix() == 2); Require(chmod_nid_postfix("anyps5_missing_chmod_path", 0600) == -1 && *__error_nid_postfix() == 2); Require(sceKernelChmod_nid_postfix("anyps5_missing_chmod_path", 0600) == static_cast(0x80020002u)); + Require(sceKernelStat("anyps5_missing_chmod_path", nullptr) == static_cast(0x80020002u)); + Require(sceKernelStat(".", nullptr) == static_cast(0x8002000eu)); Require(sceKernelDebugOutText(-1, "text") == static_cast(0x80020016u)); std::uint64_t throttling[4] = {1, 2, 3, 4}; Require(sceKernelWriteThrottlingStatus(throttling) == 0);