Skip to content

Commit 2cb8453

Browse files
committed
fix: string termination in sysctlbyname
1 parent f501eca commit 2cb8453

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

PlayTools/PlayLoader.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int pt_sysctl(int *name, u_int types, void *buf, size_t *size, void *arg0
6161
}
6262

6363
static int pt_sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) {
64-
if ((strcmp(name, "hw.machine") == 0) || (strcmp(name, "hw.product") == 0) || (strcmp(name, "hw.model") == 0)) {
64+
if ((strcmp(name, "hw.product") == 0) || (strcmp(name, "hw.model") == 0)) {
6565
if (oldp == NULL) {
6666
int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen);
6767
// We don't want to accidentally decrease it because the real sysctl call will ENOMEM
@@ -75,6 +75,7 @@ static int pt_sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *
7575
int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen);
7676
const char *machine = DEVICE_MODEL;
7777
strncpy((char *)oldp, machine, strlen(machine));
78+
((char *)oldp)[strlen(machine)] = '\0';
7879
*oldlenp = strlen(machine) + 1;
7980
return ret;
8081
} else {
@@ -92,6 +93,7 @@ static int pt_sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *
9293
int ret = sysctlbyname(name, oldp, oldlenp, newp, newlen);
9394
const char *machine = OEM_ID;
9495
strncpy((char *)oldp, machine, strlen(machine));
96+
((char *)oldp)[strlen(machine)] = '\0';
9597
*oldlenp = strlen(machine) + 1;
9698
return ret;
9799
} else {

0 commit comments

Comments
 (0)