Merge pull request #5367 from MarcZX100/marc/sysctl-leaf-enotdir-5356

fix(libkernel): return ENOTDIR for trailing sysctl leaf components
This commit is contained in:
Dean 2026-10-14 16:41:21 +13:00 committed by GitHub
commit a31043146e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -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);

View File

@ -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();