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

Commit 3502589

Browse files
Olga Batyshkinabnoordhuis
authored andcommitted
Disallow empty Content-Length
PR-URL: #459 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent cd88eef commit 3502589

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

http_parser.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,11 @@ size_t http_parser_execute (http_parser *parser,
17401740
case h_transfer_encoding_chunked:
17411741
parser->flags |= F_CHUNKED;
17421742
break;
1743+
case h_content_length:
1744+
/* do not allow empty content length */
1745+
SET_ERRNO(HPE_INVALID_CONTENT_LENGTH);
1746+
goto error;
1747+
break;
17431748
default:
17441749
break;
17451750
}

test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4182,6 +4182,13 @@ main (void)
41824182
test_invalid_header_field_token_error(HTTP_RESPONSE);
41834183
test_invalid_header_field_content_error(HTTP_RESPONSE);
41844184

4185+
test_simple_type(
4186+
"POST / HTTP/1.1\r\n"
4187+
"Content-Length:\r\n" // empty
4188+
"\r\n",
4189+
HPE_INVALID_CONTENT_LENGTH,
4190+
HTTP_REQUEST);
4191+
41854192
test_simple_type(
41864193
"POST / HTTP/1.1\r\n"
41874194
"Content-Length: 42 \r\n" // Note the surrounding whitespace.

0 commit comments

Comments
 (0)