From b68ad3626c84facfa9652abd8e71b42613b4f003 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 30 Apr 2026 09:31:28 +0800 Subject: [PATCH] Sysctl: returns error on failed string fetch and removes malloc null check Co-authored-by: Copilot --- src/common/impl/sysctl.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/common/impl/sysctl.c b/src/common/impl/sysctl.c index 62268754a..597469814 100644 --- a/src/common/impl/sysctl.c +++ b/src/common/impl/sysctl.c @@ -47,10 +47,12 @@ const char* ffSysctlGetString(const char* propName, FFstrbuf* result) { ffStrbufEnsureFree(result, (uint32_t) neededLength - 1); - if (sysctlbyname(propName, result->chars + result->length, &neededLength, NULL, 0) == 0) { - result->length += (uint32_t) neededLength - 1; + if (sysctlbyname(propName, result->chars + result->length, &neededLength, NULL, 0) != 0) { + return "sysctlbyname() failed to retrieve string data"; } + result->length += (uint32_t) neededLength - 1; + result->chars[result->length] = '\0'; return NULL; @@ -81,9 +83,6 @@ void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength) { } void* data = malloc(*resultLength); - if (data == NULL) { - return NULL; - } if (sysctl(request, requestLength, data, resultLength, NULL, 0) != 0) { free(data);