Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -28,10 +28,12 @@ #import "OFDictionary.h" #import "OFDataArray.h" #import "OFAutoreleasePool.h" #import "OFHTTPRequestFailedException.h" +#import "OFInvalidEncodingException.h" +#import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" @@ -274,24 +276,42 @@ [sock setBuffersWrites: NO]; if (requestType == OF_HTTP_REQUEST_TYPE_POST) [sock writeString: queryString]; - line = [sock readLine]; + @try { + line = [sock readLine]; + } @catch (OFInvalidEncodingException *e) { + @throw [OFInvalidServerReplyException exceptionWithClass: isa]; + } + if (![line hasPrefix: @"HTTP/1.0 "] && ![line hasPrefix: @"HTTP/1.1 "]) @throw [OFInvalidServerReplyException exceptionWithClass: isa]; status = (int)[[line substringWithRange: of_range(9, 3)] decimalValue]; serverHeaders = [OFMutableDictionary dictionary]; - while ((line = [sock readLine]) != nil) { + for (;;) { OFString *key, *value; - const char *line_c = [line UTF8String], *tmp; + const char *line_c, *tmp; + + @try { + line = [sock readLine]; + } @catch (OFInvalidEncodingException *e) { + @throw [OFInvalidServerReplyException + exceptionWithClass: isa]; + } + + if (line == nil) + @throw [OFInvalidServerReplyException + exceptionWithClass: isa]; if ([line isEqual: @""]) break; + + line_c = [line UTF8String]; if ((tmp = strchr(line_c, ':')) == NULL) @throw [OFInvalidServerReplyException exceptionWithClass: isa]; @@ -360,19 +380,31 @@ if (chunked) { for (;;) { size_t pos, toRead; - line = [sock readLine]; + @try { + line = [sock readLine]; + } @catch (OFInvalidEncodingException *e) { + @throw [OFInvalidServerReplyException + exceptionWithClass: isa]; + } pos = [line indexOfFirstOccurrenceOfString: @";"]; if (pos != OF_INVALID_INDEX) line = [line substringWithRange: of_range(0, pos)]; - toRead = (size_t)[line hexadecimalValue]; + @try { + toRead = + (size_t)[line hexadecimalValue]; + } @catch (OFInvalidFormatException *e) { + @throw [OFInvalidServerReplyException + exceptionWithClass: isa]; + } + if (toRead == 0) break; while (toRead > 0) { size_t length = (toRead < of_pagesize @@ -391,11 +423,18 @@ fromCArray: buffer]; toRead -= length; } - if (![[sock readLine] isEqual: @""]) + @try { + line = [sock readLine]; + } @catch (OFInvalidEncodingException *e) { + @throw [OFInvalidServerReplyException + exceptionWithClass: isa]; + } + + if (![line isEqual: @""]) @throw [OFInvalidServerReplyException exceptionWithClass: isa]; [pool2 releaseObjects]; }