Skip to content

Commit

Permalink
Fixed possible SIGABRT in dateFromISO8601String
Browse files Browse the repository at this point in the history
Fixed possible SIGABRT in dateFromISO8601String due to strncpy writing past the end of the stack buffer
  • Loading branch information
cbrauchli committed Mar 10, 2012
1 parent 9cc007c commit 58afb57
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions SSToolkit/NSDate+SSToolkitAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ + (NSDate *)dateFromISO8601String:(NSString *)iso8601 {
}

const char *str = [iso8601 cStringUsingEncoding:NSUTF8StringEncoding];
char newStr[24];
char newStr[25];

struct tm tm;
size_t len = strlen(str);
Expand All @@ -29,7 +29,7 @@ + (NSDate *)dateFromISO8601String:(NSString *)iso8601 {
// UTC
if (len == 20 && str[len - 1] == 'Z') {
strncpy(newStr, str, len - 1);
strncpy(newStr + len - 1, "+0000\0", 6);
strncpy(newStr + len - 1, "+0000", 5);
}

// Timezone
Expand All @@ -43,6 +43,9 @@ + (NSDate *)dateFromISO8601String:(NSString *)iso8601 {
strncpy(newStr, str, len > 24 ? 24 : len);
}

// Add null terminator
newStr[sizeof(newStr) - 1] = 0;

if (strptime(newStr, "%FT%T%z", &tm) == NULL) {
return nil;
}
Expand Down

0 comments on commit 58afb57

Please sign in to comment.