Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Commit cd88eef

Browse files
Olga Batyshkinabnoordhuis
authored andcommitted
Fix Content-Length with obsolete line folding
Content-Length with line folding was accepted with invalid input. Treat obsolete line folding as space and continue parsing Fixes: #456 PR-URL: #458 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 0ae8d93 commit cd88eef

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

http_parser.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,11 @@ size_t http_parser_execute (http_parser *parser,
14361436
parser->header_state = h_content_length_num;
14371437
break;
14381438

1439+
/* when obsolete line folding is encountered for content length
1440+
* continue to the s_header_value state */
1441+
case h_content_length_ws:
1442+
break;
1443+
14391444
case h_connection:
14401445
/* looking for 'Connection: keep-alive' */
14411446
if (c == 'k') {
@@ -1679,6 +1684,10 @@ size_t http_parser_execute (http_parser *parser,
16791684
case s_header_value_lws:
16801685
{
16811686
if (ch == ' ' || ch == '\t') {
1687+
if (parser->header_state == h_content_length_num) {
1688+
/* treat obsolete line folding as space */
1689+
parser->header_state = h_content_length_ws;
1690+
}
16821691
UPDATE_STATE(s_header_value_start);
16831692
REEXECUTE();
16841693
}

test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,6 +4203,20 @@ main (void)
42034203
HPE_INVALID_CONTENT_LENGTH,
42044204
HTTP_REQUEST);
42054205

4206+
test_simple_type(
4207+
"POST / HTTP/1.1\r\n"
4208+
"Content-Length: 42\r\n"
4209+
" Hello world!\r\n",
4210+
HPE_INVALID_CONTENT_LENGTH,
4211+
HTTP_REQUEST);
4212+
4213+
test_simple_type(
4214+
"POST / HTTP/1.1\r\n"
4215+
"Content-Length: 42\r\n"
4216+
" \r\n",
4217+
HPE_OK,
4218+
HTTP_REQUEST);
4219+
42064220
//// RESPONSES
42074221

42084222
test_simple_type("HTP/1.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);

0 commit comments

Comments
 (0)