Skip to content

Commit

Permalink
Merge pull request #11 from dapatil/master
Browse files Browse the repository at this point in the history
Fixed a buffer overflow in stringByRegex
  • Loading branch information
artifacts committed Mar 7, 2012
2 parents ec57069 + 7a69743 commit ca5ca13
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/3rdparty/AFRegexString/AFRegexString.m
Expand Up @@ -84,8 +84,14 @@ - (NSString *)stringByRegex:(NSString*)pattern substitution:(NSString*)substitut
}
else
{
char buf[4096];
strcpy(buf, [self UTF8String]);
char buffer[4096];
char *buf = buffer;
const char *utf8String = [self UTF8String];

if(strlen(utf8String) >= sizeof(buffer))
buf = malloc(strlen(utf8String) + 1);

strcpy(buf, utf8String);
char *replaceStr = (char*)[substitute UTF8String];

if (rreplace (buf, 4096, &preg, replaceStr))
Expand All @@ -98,6 +104,9 @@ - (NSString *)stringByRegex:(NSString*)pattern substitution:(NSString*)substitut
{
result = [NSString stringWithUTF8String:buf];
}

if(buf != buffer)
free(buf);
}


Expand Down

0 comments on commit ca5ca13

Please sign in to comment.