ObjFW  Check-in [9e647a2ddd]

Overview
Comment:OFHTTPRequest: Check Content-Length if present to check for truncation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9e647a2ddd414c64f9a63bbebdbfd063e4012922f9d6a5d418c56f711ccb7c18
User & Date: js on 2011-02-25 12:14:54
Other Links: manifest | tags
Context
2011-02-25
15:22
Fix a stupid bug in OFHTTPRequest. check-in: 70e1297f87 user: js tags: trunk
12:14
OFHTTPRequest: Check Content-Length if present to check for truncation. check-in: 9e647a2ddd user: js tags: trunk
12:02
OFHTTPRequest: Work around a bug in lighttpd with HTTPS. check-in: 73c723bf39 user: js tags: trunk
Changes

Modified src/OFExceptions.h from [8168934e0a] to [7ada383252].

1324
1325
1326
1327
1328
1329
1330







- (OFHTTPRequest*)HTTPRequest;

/**
 * \return The status code of the HTTP request
 */
- (short)statusCode;
@end














>
>
>
>
>
>
>
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
- (OFHTTPRequest*)HTTPRequest;

/**
 * \return The status code of the HTTP request
 */
- (short)statusCode;
@end

/**
 * \brief An exception indicating that data was truncated while it should not
 *	  have been truncated.
 */
@interface OFTruncatedDataException: OFException
@end

Modified src/OFExceptions.m from [9ed6a2db34] to [52c201d27f].

1970
1971
1972
1973
1974
1975
1976














}

- (short)statusCode
{
	return statusCode;
}
@end





















>
>
>
>
>
>
>
>
>
>
>
>
>
>
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
}

- (short)statusCode
{
	return statusCode;
}
@end

@implementation OFTruncatedDataException
- (OFString*)description
{
	if (description != nil)
		return description;

	description = [[OFString alloc] initWithFormat:
	    @"Truncated data was received or produced in class %s while it "
	    @"should not have been truncated!", class_getName(inClass)];

	return description;
}
@end

Modified src/OFHTTPRequest.m from [af54b95e34] to [be1d7818d7].

259
260
261
262
263
264
265















266
267
268
269
270
271
272
			}

			[s_headers setObject: value
				      forKey: key];
		}

		data = [[sock readDataArrayTillEndOfStream] retain];
















		result = [[OFHTTPRequestResult alloc]
		    initWithStatusCode: status
			       headers: s_headers
				  data: data];
	} @finally {
		[pool release];







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
			}

			[s_headers setObject: value
				      forKey: key];
		}

		data = [[sock readDataArrayTillEndOfStream] retain];

		if ([s_headers objectForKey: @"Content-Length"] != nil) {
			intmax_t cl;

			cl = [[s_headers objectForKey: @"Content-Length"]
			    decimalValue];

			if (cl > SIZE_MAX)
				@throw [OFOutOfRangeException
				    newWithClass: isa];

			if (cl != [data count])
				@throw [OFTruncatedDataException
				    newWithClass: isa];
		}

		result = [[OFHTTPRequestResult alloc]
		    initWithStatusCode: status
			       headers: s_headers
				  data: data];
	} @finally {
		[pool release];