ObjFW  Check-in [2fb248a952]

Overview
Comment:OFHTTPServer: Fix handling of Host:.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2fb248a952ccd628f3ff9b382408fbf33850e3037acb898d92f467a1ae0614c6
User & Date: js on 2012-12-15 19:36:28
Other Links: manifest | tags
Context
2012-12-15
19:44
Get rid of a wrongful GCC warning. check-in: a7e0ceee3a user: js tags: trunk
19:36
OFHTTPServer: Fix handling of Host:. check-in: 2fb248a952 user: js tags: trunk
17:52
OFDataArray: Improve API. check-in: c85ff8d35a user: js tags: trunk
Changes

Modified src/OFHTTPServer.m from [61524a3f46] to [0a1464d83e].

363
364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386

387
388
389
390
391
392
393

	if ([key isEqual: @"Host"]) {
		pos = [value
		    rangeOfString: @":"
			  options: OF_STRING_SEARCH_BACKWARDS].location;

		if (pos != OF_NOT_FOUND) {

			host = [[value substringWithRange:
			    of_range(0, pos)] retain];

			@try {
				of_range_t range =
				    of_range(pos + 1, [value length] - pos - 1);
				intmax_t portTmp = [[value
				    substringWithRange: range] decimalValue];

				if (portTmp < 1 || portTmp > UINT16_MAX)
					return [self sendErrorAndClose: 400];

				port = (uint16_t)portTmp;
			} @catch (OFInvalidFormatException *e) {
				return [self sendErrorAndClose: 400];
			}
		} else {

			host = [value retain];
			port = 80;
		}
	}

	return YES;
}







>

















>







363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395

	if ([key isEqual: @"Host"]) {
		pos = [value
		    rangeOfString: @":"
			  options: OF_STRING_SEARCH_BACKWARDS].location;

		if (pos != OF_NOT_FOUND) {
			[host release];
			host = [[value substringWithRange:
			    of_range(0, pos)] retain];

			@try {
				of_range_t range =
				    of_range(pos + 1, [value length] - pos - 1);
				intmax_t portTmp = [[value
				    substringWithRange: range] decimalValue];

				if (portTmp < 1 || portTmp > UINT16_MAX)
					return [self sendErrorAndClose: 400];

				port = (uint16_t)portTmp;
			} @catch (OFInvalidFormatException *e) {
				return [self sendErrorAndClose: 400];
			}
		} else {
			[host release];
			host = [value retain];
			port = 80;
		}
	}

	return YES;
}
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458

	if (host == nil || port == 0) {
		if (HTTPMinorVersion > 0) {
			[self sendErrorAndClose: 400];
			return;
		}

		host = [server host];
		port = [server port];
	}

	URL = [OFURL URL];
	[URL setScheme: @"http"];
	[URL setHost: host];
	[URL setPort: port];







|







446
447
448
449
450
451
452
453
454
455
456
457
458
459
460

	if (host == nil || port == 0) {
		if (HTTPMinorVersion > 0) {
			[self sendErrorAndClose: 400];
			return;
		}

		host = [[server host] retain];
		port = [server port];
	}

	URL = [OFURL URL];
	[URL setScheme: @"http"];
	[URL setHost: host];
	[URL setPort: port];