Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -31,10 +31,11 @@ #import "OFHTTPRequestFailedException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" +#import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFUnsupportedVersionException.h" @@ -42,13 +43,12 @@ #import "macros.h" Class of_http_client_tls_socket_class = Nil; static OF_INLINE void -normalizeKey(OFString *key) +normalizeKey(char *str) { - uint8_t *str = (uint8_t*)[key UTF8String]; BOOL firstLetter = YES; while (*str != '\0') { if (!isalnum(*str)) { firstLetter = YES; @@ -246,10 +246,11 @@ serverHeaders = [OFMutableDictionary dictionary]; for (;;) { OFString *key, *value; const char *line_c, *tmp; + char *key_c; @try { line = [sock readLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException @@ -267,13 +268,25 @@ if ((tmp = strchr(line_c, ':')) == NULL) @throw [OFInvalidServerReplyException exceptionWithClass: [self class]]; - key = [OFString stringWithUTF8String: line_c - length: tmp - line_c]; - normalizeKey(key); + if ((key_c = malloc(tmp - line_c + 1)) == NULL) + @throw [OFOutOfMemoryException + exceptionWithClass: [self class] + requestedSize: tmp - line_c + 1]; + + memcpy(key_c, line_c, tmp - line_c); + key_c[tmp - line_c] = '\0'; + normalizeKey(key_c); + + @try { + key = [OFString stringWithUTF8StringNoCopy: key_c + freeWhenDone: YES]; + } @catch (id e) { + free(key_c); + } do { tmp++; } while (*tmp == ' ');