Skip to content

Commit 056342d

Browse files
dloicpaulb777
authored andcommitted
Be sure to validate return code when calling sysctlbyname function (C… (#2394)
1 parent b7a5b34 commit 056342d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Firebase/DynamicLinks/Utilities/FDLUtilities.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,16 @@ BOOL FIRDLOSVersionSupported(NSString *_Nullable systemVersion, NSString *minSup
169169
static dispatch_once_t onceToken;
170170
dispatch_once(&onceToken, ^{
171171
size_t size;
172-
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
173-
char *machine = calloc(1, size);
174-
sysctlbyname("hw.machine", machine, &size, NULL, 0);
175-
machineString = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
176-
free(machine);
172+
173+
// compute string size
174+
if (sysctlbyname("hw.machine", NULL, &size, NULL, 0) == 0) {
175+
// get device name
176+
char *machine = calloc(1, size);
177+
if (sysctlbyname("hw.machine", machine, &size, NULL, 0) == 0) {
178+
machineString = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
179+
}
180+
free(machine);
181+
}
177182
});
178183
return machineString;
179184
}

0 commit comments

Comments
 (0)