mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-05 13:20:11 +00:00
Merge pull request #8603 from xXPBSXx/fix/libkernel-sys-readlink-size-first
fix(libkernel_sys): check the readlink size before the path
This commit is contained in:
2 files changed
+9
-2
No files matched your search
@@ -273,18 +273,18 @@ int APS5_VABI fstatfs_nid_postfix(int d, void* buf) {
|
||||
}
|
||||
|
||||
std::int64_t APS5_VABI readlink_nid_postfix(const char* path, char* buffer, std::size_t size) {
|
||||
if (size > static_cast<std::size_t>(std::numeric_limits<std::int64_t>::max())) return Fail(GuestEinval);
|
||||
if (path == nullptr) return Fail(GuestEfault);
|
||||
if (*path == '\0') return Fail(GuestEnoent);
|
||||
if (size > static_cast<std::size_t>(std::numeric_limits<std::int64_t>::max())) return Fail(GuestEinval);
|
||||
std::filesystem::path native;
|
||||
if (const int error = ResolvePathError_nid_no_patch(path, native)) return Fail(error);
|
||||
return ReadNativeLink(native, buffer, size);
|
||||
}
|
||||
|
||||
std::int64_t APS5_VABI readlinkat_nid_postfix(int fd, const char* path, char* buffer, std::size_t size) {
|
||||
if (size > static_cast<std::size_t>(std::numeric_limits<std::int64_t>::max())) return Fail(GuestEinval);
|
||||
if (path == nullptr) return Fail(GuestEfault);
|
||||
if (*path == '\0') return Fail(GuestEnoent);
|
||||
if (size > static_cast<std::size_t>(std::numeric_limits<std::int64_t>::max())) return Fail(GuestEinval);
|
||||
if (fd == GuestAtFdcwd || *path == '/') return readlink_nid_postfix(path, buffer, size);
|
||||
int error = 0;
|
||||
const char* base = GetDirectoryDescriptorPath_nid_no_patch(fd, &error);
|
||||
|
||||
@@ -300,6 +300,13 @@ int main() {
|
||||
Require(readlink_nid_postfix((root / "missing").string().c_str(), buffer, sizeof(buffer)) == -1 && Error() == 2);
|
||||
Require(readlink_nid_postfix("", buffer, sizeof(buffer)) == -1 && Error() == 2);
|
||||
Require(readlink_nid_postfix(nullptr, buffer, sizeof(buffer)) == -1 && Error() == 14);
|
||||
constexpr auto hugeSize = static_cast<std::size_t>(-1);
|
||||
Require(readlink_nid_postfix(nullptr, buffer, hugeSize) == -1 && Error() == 22);
|
||||
Require(readlink_nid_postfix("", buffer, hugeSize) == -1 && Error() == 22);
|
||||
Require(readlink_nid_postfix((root / "missing").string().c_str(), buffer, hugeSize) == -1 && Error() == 22);
|
||||
Require(readlinkat_nid_postfix(-100, nullptr, buffer, hugeSize) == -1 && Error() == 22);
|
||||
Require(readlinkat_nid_postfix(-100, "", buffer, hugeSize) == -1 && Error() == 22);
|
||||
Require(readlinkat_nid_postfix(-100, nullptr, buffer, sizeof(buffer)) == -1 && Error() == 14);
|
||||
#ifndef _WIN32
|
||||
Require(readlink_nid_postfix((root / std::string(300, 'n')).string().c_str(), buffer, sizeof(buffer)) == -1 && Error() == 63);
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user