diff --git a/core/libs/prx/libkernel/System/src/SystemConfiguration.cpp b/core/libs/prx/libkernel/System/src/SystemConfiguration.cpp index c6a0c3ca4..6f73881e8 100644 --- a/core/libs/prx/libkernel/System/src/SystemConfiguration.cpp +++ b/core/libs/prx/libkernel/System/src/SystemConfiguration.cpp @@ -45,6 +45,10 @@ int CopyOut(const void* value, std::size_t size, void* oldValue, std::size_t* ol return 0; } +bool IsLeafMib(const int* name) { + return (name[0] == 6 && (name[1] == 2 || name[1] == 3 || name[1] == 5)) || (name[0] == 1 && name[1] == 37); +} + std::string HostCpuModel() { #if defined(__x86_64__) || defined(__i386__) if (__get_cpuid_max(0x80000000, nullptr) < 0x80000004) return {}; @@ -173,6 +177,10 @@ int APS5_VABI sysctl_nid_postfix(const int* name, std::uint32_t nameLength, void *oldLength = count; return 0; } + if (nameLength > 2 && IsLeafMib(name)) { + *__error_nid_postfix() = 20; + return -1; + } std::string mib; for (std::uint32_t i = 0; i < nameLength; ++i) mib += (i == 0 ? "" : ".") + std::to_string(name[i]); throw std::runtime_error(std::string(__func__) + ": unsupported MIB " + mib); diff --git a/core/libs/tests/GuestSystemConfiguration.cpp b/core/libs/tests/GuestSystemConfiguration.cpp index 2e362eec1..531bb4d80 100644 --- a/core/libs/tests/GuestSystemConfiguration.cpp +++ b/core/libs/tests/GuestSystemConfiguration.cpp @@ -176,6 +176,18 @@ static void CheckPathnameSysctl() { length = sizeof(buffer); Require(sysctl_nid_postfix(mibSelf, 4, buffer, &length, buffer, sizeof(buffer)) == -1 && *__error_nid_postfix() == 1); } +static void CheckLeafWithTrailingComponent() { + const int leaves[][2] = {{6, 3}, {6, 2}, {6, 5}, {1, 37}}; + for (const auto& leaf : leaves) { + const int mib[] = {leaf[0], leaf[1], 0}; + char buffer[8] = {}; + std::size_t length = sizeof(buffer); + *__error_nid_postfix() = 13; + Require(sysctl_nid_postfix(mib, 3, buffer, &length, nullptr, 0) == -1 && *__error_nid_postfix() == 20); + Require(sysctl_nid_postfix(mib, 3, buffer, &length, buffer, sizeof(buffer)) == -1 && *__error_nid_postfix() == 20); + Require(length == sizeof(buffer)); + } +} static void CheckSystemSwVersion() { *__error_nid_postfix() = 13; Require(sceKernelGetSystemSwVersion_nid_postfix(nullptr) == SCE_KERNEL_ERROR_EFAULT && *__error_nid_postfix() == 13); @@ -300,6 +312,7 @@ int main() { CheckTscFrequencySysctl(); CheckMachdepCachelineSizeSysctl(); CheckPathnameSysctl(); + CheckLeafWithTrailingComponent(); CheckSystemSwVersion(); CheckPseudoRandomSysctl(); CheckSdkVersionSysctl();