File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -370,6 +370,8 @@ enum header_states
370
370
371
371
, h_connection
372
372
, h_content_length
373
+ , h_content_length_num
374
+ , h_content_length_ws
373
375
, h_transfer_encoding
374
376
, h_upgrade
375
377
@@ -1406,6 +1408,7 @@ size_t http_parser_execute (http_parser *parser,
1406
1408
1407
1409
parser -> flags |= F_CONTENTLENGTH ;
1408
1410
parser -> content_length = ch - '0' ;
1411
+ parser -> header_state = h_content_length_num ;
1409
1412
break ;
1410
1413
1411
1414
case h_connection :
@@ -1493,10 +1496,18 @@ size_t http_parser_execute (http_parser *parser,
1493
1496
break ;
1494
1497
1495
1498
case h_content_length :
1499
+ if (ch == ' ' ) break ;
1500
+ h_state = h_content_length_num ;
1501
+ /* FALLTHROUGH */
1502
+
1503
+ case h_content_length_num :
1496
1504
{
1497
1505
uint64_t t ;
1498
1506
1499
- if (ch == ' ' ) break ;
1507
+ if (ch == ' ' ) {
1508
+ h_state = h_content_length_ws ;
1509
+ break ;
1510
+ }
1500
1511
1501
1512
if (UNLIKELY (!IS_NUM (ch ))) {
1502
1513
SET_ERRNO (HPE_INVALID_CONTENT_LENGTH );
@@ -1519,6 +1530,12 @@ size_t http_parser_execute (http_parser *parser,
1519
1530
break ;
1520
1531
}
1521
1532
1533
+ case h_content_length_ws :
1534
+ if (ch == ' ' ) break ;
1535
+ SET_ERRNO (HPE_INVALID_CONTENT_LENGTH );
1536
+ parser -> header_state = h_state ;
1537
+ goto error ;
1538
+
1522
1539
/* Transfer-Encoding: chunked */
1523
1540
case h_matching_transfer_encoding_chunked :
1524
1541
parser -> index ++ ;
Original file line number Diff line number Diff line change @@ -4168,6 +4168,27 @@ main (void)
4168
4168
test_invalid_header_field_token_error (HTTP_RESPONSE );
4169
4169
test_invalid_header_field_content_error (HTTP_RESPONSE );
4170
4170
4171
+ test_simple_type (
4172
+ "POST / HTTP/1.1\r\n"
4173
+ "Content-Length: 42 \r\n" // Note the surrounding whitespace.
4174
+ "\r\n" ,
4175
+ HPE_OK ,
4176
+ HTTP_REQUEST );
4177
+
4178
+ test_simple_type (
4179
+ "POST / HTTP/1.1\r\n"
4180
+ "Content-Length: 4 2\r\n"
4181
+ "\r\n" ,
4182
+ HPE_INVALID_CONTENT_LENGTH ,
4183
+ HTTP_REQUEST );
4184
+
4185
+ test_simple_type (
4186
+ "POST / HTTP/1.1\r\n"
4187
+ "Content-Length: 13 37\r\n"
4188
+ "\r\n" ,
4189
+ HPE_INVALID_CONTENT_LENGTH ,
4190
+ HTTP_REQUEST );
4191
+
4171
4192
//// RESPONSES
4172
4193
4173
4194
test_simple_type ("HTP/1.1 200 OK\r\n\r\n" , HPE_INVALID_VERSION , HTTP_RESPONSE );
You can’t perform that action at this time.
0 commit comments