mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-12-04 16:40:32 +00:00
Merge pull request #24314 from vishnuvardhan3333/fix/shell-ui-util-guest-pointers
fix(libSceShellUIUtil): validate guest string and output pointers in get app url and launch functions
This commit is contained in:
3 files changed
+42
-3
No files matched your search
@@ -5,6 +5,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/General.hpp"
|
||||
@@ -22,8 +23,21 @@ std::recursive_mutex g_mutex;
|
||||
bool g_initialized = false;
|
||||
std::atomic<std::uint32_t> g_taskTokens{0};
|
||||
|
||||
bool IsValidGuestWrite(void* pointer, std::size_t size) {
|
||||
if (pointer == nullptr) return false;
|
||||
const int savedErrno = errno;
|
||||
const bool writable = GuestWritable_nid_no_patch(pointer, size != 0 ? size : 1);
|
||||
errno = savedErrno;
|
||||
return writable;
|
||||
}
|
||||
|
||||
bool StringTooLong(const char* text) {
|
||||
return strnlen(text, StringLimit) > StringLimit - 1;
|
||||
if (text == nullptr) return true;
|
||||
std::string copy;
|
||||
const int savedErrno = errno;
|
||||
const int error = CopyGuestString_nid_no_patch(text, StringLimit, copy);
|
||||
errno = savedErrno;
|
||||
return error != 0 || copy.length() > StringLimit - 1;
|
||||
}
|
||||
|
||||
int CallService(const char* name) {
|
||||
@@ -48,11 +62,13 @@ int APS5_VABI sceShellUIUtilCreateTaskToken() {
|
||||
}
|
||||
|
||||
int APS5_VABI sceShellUIUtilGetAppUrl(const char* application, const char* parameter, char* output, std::uint32_t capacity, std::uint32_t* outputSize) {
|
||||
(void)outputSize;
|
||||
if (application == nullptr || parameter == nullptr || StringTooLong(application)) {
|
||||
return ErrorInvalidArgument;
|
||||
}
|
||||
if (capacity > AppUrlCapacityLimit || StringTooLong(parameter) || (capacity != 0 && output == nullptr)) {
|
||||
if (capacity > AppUrlCapacityLimit || StringTooLong(parameter) || (capacity != 0 && !IsValidGuestWrite(output, capacity))) {
|
||||
return ErrorInvalidArgument;
|
||||
}
|
||||
if (outputSize != nullptr && !IsValidGuestWrite(outputSize, sizeof(*outputSize))) {
|
||||
return ErrorInvalidArgument;
|
||||
}
|
||||
return CallService(__func__);
|
||||
|
||||
@@ -34,6 +34,18 @@ void CheckArguments() {
|
||||
Require(sceShellUIUtilGetAppUrl("a", longText.c_str(), output, 16, &size) == InvalidArgument, "GetAppUrl: long parameter");
|
||||
Require(sceShellUIUtilGetAppUrl("a", "p", output, 0x1001, &size) == InvalidArgument, "GetAppUrl: capacity");
|
||||
Require(sceShellUIUtilGetAppUrl("a", "p", nullptr, 16, &size) == InvalidArgument, "GetAppUrl: null output");
|
||||
errno = 71;
|
||||
Require(sceShellUIUtilGetAppUrl(reinterpret_cast<const char*>(0x10), "p", output, 16, &size) == InvalidArgument, "GetAppUrl: unreadable application");
|
||||
Require(errno == 71, "GetAppUrl: errno preserved for application");
|
||||
errno = 71;
|
||||
Require(sceShellUIUtilGetAppUrl("a", reinterpret_cast<const char*>(0x10), output, 16, &size) == InvalidArgument, "GetAppUrl: unreadable parameter");
|
||||
Require(errno == 71, "GetAppUrl: errno preserved for parameter");
|
||||
errno = 71;
|
||||
Require(sceShellUIUtilGetAppUrl("a", "p", reinterpret_cast<char*>(0x10), 16, &size) == InvalidArgument, "GetAppUrl: unwritable output");
|
||||
Require(errno == 71, "GetAppUrl: errno preserved for output");
|
||||
errno = 71;
|
||||
Require(sceShellUIUtilGetAppUrl("a", "p", output, 16, reinterpret_cast<std::uint32_t*>(0x10)) == InvalidArgument, "GetAppUrl: unwritable outputSize");
|
||||
Require(errno == 71, "GetAppUrl: errno preserved for outputSize");
|
||||
Require(sceShellUIUtilGetAppUrl(longestText.c_str(), longestText.c_str(), nullptr, 0, nullptr) == NotInitialized,
|
||||
"GetAppUrl: the longest strings, no output, before Initialize");
|
||||
Require(sceShellUIUtilGetAppUrl("a", "p", output, 0x1000, nullptr) == NotInitialized, "GetAppUrl: capacity 0x1000");
|
||||
@@ -46,6 +58,9 @@ void CheckArguments() {
|
||||
Require(sceShellUIUtilLaunchByUri(nullptr, LaunchParameter(good)) == InvalidArgument, "LaunchByUri: null uri");
|
||||
Require(sceShellUIUtilLaunchByUri("u", nullptr) == InvalidArgument, "LaunchByUri: null parameter");
|
||||
errno = 71;
|
||||
Require(sceShellUIUtilLaunchByUri(reinterpret_cast<const char*>(0x10), LaunchParameter(good)) == InvalidArgument, "LaunchByUri: unreadable uri");
|
||||
Require(errno == 71, "LaunchByUri: errno preserved for uri");
|
||||
errno = 71;
|
||||
Require(sceShellUIUtilLaunchByUri("u", reinterpret_cast<const ShellUIUtilLaunchParameter*>(0x10)) == InvalidArgument, "LaunchByUri: unreadable parameter");
|
||||
Require(errno == 71, "LaunchByUri: errno preserved");
|
||||
Require(sceShellUIUtilLaunchByUri(longText.c_str(), LaunchParameter(good)) == InvalidArgument, "LaunchByUri: long uri");
|
||||
@@ -56,6 +71,9 @@ void CheckArguments() {
|
||||
Require(sceShellUIUtilLaunchTask(1, "u", taskOutput.data(), 0xFFF) == InvalidArgument, "LaunchTask: capacity");
|
||||
Require(sceShellUIUtilLaunchTask(1, "u", nullptr, 0x1000) == InvalidArgument, "LaunchTask: null output");
|
||||
errno = 71;
|
||||
Require(sceShellUIUtilLaunchTask(1, reinterpret_cast<const char*>(0x10), taskOutput.data(), 0x1000) == InvalidArgument, "LaunchTask: unreadable uri");
|
||||
Require(errno == 71, "LaunchTask: errno preserved for uri");
|
||||
errno = 71;
|
||||
Require(sceShellUIUtilLaunchTask(1, "u", reinterpret_cast<char*>(0x10), 0x1000) == InvalidArgument, "LaunchTask: unwritable output");
|
||||
Require(errno == 71, "LaunchTask: errno preserved");
|
||||
Require(sceShellUIUtilLaunchTask(1, longText.c_str(), taskOutput.data(), 0x1000) == InvalidArgument, "LaunchTask: long uri");
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# libSceShellUIUtil
|
||||
|
||||
## change [sceShellUIUtilLaunchByUri and sceShellUIUtilLaunchTask pointer safety]
|
||||
|
||||
- [sceShellUIUtilLaunchByUri, sceShellUIUtilLaunchTask and sceShellUIUtilGetAppUrl pointer safety](../../../core/libs/prx/libSceShellUIUtil/Export.cpp): unreadable URI and launch parameter pointers in `sceShellUIUtilLaunchByUri`, unreadable URI and unwritable output buffer in `sceShellUIUtilLaunchTask`, and unreadable string, unwritable output buffer (when capacity is non-zero) and unwritable output size pointers in `sceShellUIUtilGetAppUrl` return `0x80BA0020` (`ErrorInvalidArgument`) with `errno` preserved.
|
||||
Reference in new issue
Block a user