Skip to content

Commit 6b84638

Browse files
committed
Fix null-termination of system call on getting the full os version.
1 parent 038010d commit 6b84638

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Parse/Internal/PFDevice.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
if (sysctlbyname(charName, answer, &size, NULL, 0) != 0) {
4343
break;
4444
}
45-
string = [[NSString alloc] initWithBytes:answer length:size encoding:NSASCIIStringEncoding];
45+
46+
// We need to check if the string is null-terminated or not.
47+
// Documentation is silent on this fact, but in practice it actually is usually null-terminated.
48+
size_t length = size - (answer[size - 1] == '\0');
49+
string = [[NSString alloc] initWithBytes:answer length:length encoding:NSASCIIStringEncoding];
4650
} while(0);
4751

4852
free(answer);

0 commit comments

Comments
 (0)