Add testcase for multiple clookies in a header. Fix error parsing a literal

string (writing nul terminator to read only memory)
This commit is contained in:
Richard Frith-Macdonald 2020-04-16 20:19:53 +01:00
parent 3d1e84f6fe
commit 6ee0cfff00
2 changed files with 15 additions and 11 deletions

View file

@ -902,7 +902,7 @@ GSCookieStrings(NSString *string)
* separate cookie or not. We look for something of the form
* ' token =' where a space represents any optional whitespace.
*/
saved = pos;
saved = pos++;
while (pos < end && isspace(ptr[pos]))
{
pos++;
@ -939,11 +939,13 @@ GSCookieStrings(NSString *string)
}
if (saved > start)
{
const char *utf8 = (const char*)(ptr + start);
NSString *str = [NSString alloc];
ptr[saved] = '\0';
[cookies addObject:
[NSString stringWithUTF8String: utf8]];
str = [str initWithBytes: ptr + start
length: saved - start
encoding: NSUTF8StringEncoding];
[cookies addObject: str];
RELEASE(str);
}
start = saved = pos;
}
@ -966,14 +968,14 @@ GSCookieStrings(NSString *string)
}
if (saved > start)
{
NSString *str;
NSString *str = [NSString alloc];
/* There may not be room to add a nul terminator, so we use an
* initialiser which doesn't need one.
*/
str = [[NSString alloc] initWithBytes: ptr + start
length: saved - start
encoding: NSUTF8StringEncoding];
str = [str initWithBytes: ptr + start
length: saved - start
encoding: NSUTF8StringEncoding];
[cookies addObject: str];
RELEASE(str);
}