Skip to content

Commit 3793d58

Browse files
authored
fix: malloc -> calloc to fix CWE-789 vulnerability (#449)
1 parent 1928898 commit 3793d58

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/Amplitude/AMPDeviceInfo.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ + (NSString *)getPlatformString {
224224
#endif
225225
size_t size;
226226
sysctlbyname(sysctl_name, NULL, &size, NULL, 0);
227-
char *machine = malloc(size);
227+
char *machine = calloc(1, size);
228228
sysctlbyname(sysctl_name, machine, &size, NULL, 0);
229229
NSString *platform = [NSString stringWithUTF8String:machine];
230230
free(machine);
@@ -435,7 +435,7 @@ + (NSString *)getMacAddress {
435435
errorFlag = @"sysctl mgmtInfoBase failure";
436436
} else {
437437
// Alloc memory based on above call
438-
if ((msgBuffer = malloc(length)) == NULL) {
438+
if ((msgBuffer = calloc(1, length)) == NULL) {
439439
errorFlag = @"buffer allocation failure";
440440
} else {
441441
msgBufferAllocated = true;

0 commit comments

Comments
 (0)