From 251f3d146725a847a04aef01f9aa445e6259b1fd Mon Sep 17 00:00:00 2001 From: ohaiibuzzle <23693150+ohaiibuzzle@users.noreply.github.com> Date: Mon, 2 Feb 2026 21:55:34 +0700 Subject: [PATCH 1/2] fix: string termination in sysctlbyname --- PlayTools/PlayLoader.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PlayTools/PlayLoader.m b/PlayTools/PlayLoader.m index 348ab022..59ea8d0c 100644 --- a/PlayTools/PlayLoader.m +++ b/PlayTools/PlayLoader.m @@ -75,6 +75,7 @@ static int pt_sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void * int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen); const char *machine = DEVICE_MODEL; strncpy((char *)oldp, machine, strlen(machine)); + ((char *)oldp)[strlen(machine)] = '\0'; *oldlenp = strlen(machine) + 1; return ret; } else { @@ -92,6 +93,7 @@ static int pt_sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void * int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen); const char *machine = OEM_ID; strncpy((char *)oldp, machine, strlen(machine)); + ((char *)oldp)[strlen(machine)] = '\0'; *oldlenp = strlen(machine) + 1; return ret; } else { From 1004669dceb16320a2953bf61bca59bbc5ea0f7f Mon Sep 17 00:00:00 2001 From: ohaiibuzzle <23693150+ohaiibuzzle@users.noreply.github.com> Date: Tue, 3 Feb 2026 13:45:49 +0700 Subject: [PATCH 2/2] fix: why are we even calling sysctlbyname --- PlayTools/PlayLoader.m | 45 ++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/PlayTools/PlayLoader.m b/PlayTools/PlayLoader.m index 59ea8d0c..b6da6364 100644 --- a/PlayTools/PlayLoader.m +++ b/PlayTools/PlayLoader.m @@ -25,7 +25,8 @@ // Change the machine output by uname to match expected output on iOS static int pt_uname(struct utsname *uts) { uname(uts); - strncpy(uts->machine, DEVICE_MODEL, strlen(DEVICE_MODEL) + 1); + strncpy(uts->machine, DEVICE_MODEL, sizeof(uts->machine) - 1); + uts->machine[sizeof(uts->machine) - 1] = '\0'; return 0; } @@ -37,7 +38,7 @@ static int pt_sysctl(int *name, u_int types, void *buf, size_t *size, void *arg0 if (NULL == buf) { *size = strlen(DEVICE_MODEL) + 1; } else { - if (*size > strlen(DEVICE_MODEL)) { + if (*size > strlen(DEVICE_MODEL) + 1) { strcpy(buf, DEVICE_MODEL); } else { return ENOMEM; @@ -48,7 +49,7 @@ static int pt_sysctl(int *name, u_int types, void *buf, size_t *size, void *arg0 if (NULL == buf) { *size = strlen(OEM_ID) + 1; } else { - if (*size > strlen(OEM_ID)) { + if (*size > strlen(OEM_ID) + 1) { strcpy(buf, OEM_ID); } else { return ENOMEM; @@ -63,39 +64,31 @@ static int pt_sysctl(int *name, u_int types, void *buf, size_t *size, void *arg0 static int pt_sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) { if ((strcmp(name, "hw.machine") == 0) || (strcmp(name, "hw.product") == 0) || (strcmp(name, "hw.model") == 0)) { if (oldp == NULL) { - int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen); - // We don't want to accidentally decrease it because the real sysctl call will ENOMEM - // as model are much longer on Macs (eg. MacBookAir10,1) - if (*oldlenp < strlen(DEVICE_MODEL) + 1) { - *oldlenp = strlen(DEVICE_MODEL) + 1; - } - return ret; + *oldlenp = strlen(DEVICE_MODEL) + 1; + return 0; } else if (oldp != NULL) { - int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen); - const char *machine = DEVICE_MODEL; - strncpy((char *)oldp, machine, strlen(machine)); - ((char *)oldp)[strlen(machine)] = '\0'; - *oldlenp = strlen(machine) + 1; - return ret; + if (*oldlenp < strlen(DEVICE_MODEL) + 1) { + return ENOMEM; + } + strcpy((char *)oldp, DEVICE_MODEL); + *oldlenp = strlen(DEVICE_MODEL) + 1; + return 0; } else { int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen); return ret; } } else if ((strcmp(name, "hw.target") == 0)) { if (oldp == NULL) { - int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen); + *oldlenp = strlen(OEM_ID) + 1; + return 0; + } else if (oldp != NULL) { if (*oldlenp < strlen(OEM_ID) + 1) { - *oldlenp = strlen(OEM_ID) + 1; + return ENOMEM; } - return ret; - } else if (oldp != NULL) { - int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen); - const char *machine = OEM_ID; - strncpy((char *)oldp, machine, strlen(machine)); - ((char *)oldp)[strlen(machine)] = '\0'; - *oldlenp = strlen(machine) + 1; - return ret; + strcpy((char *)oldp, OEM_ID); + *oldlenp = strlen(OEM_ID) + 1; + return 0; } else { int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen); return ret;