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

Commit

Permalink
Fix multiple begin message cbs when response starts with CR/LF
Browse files Browse the repository at this point in the history
PR-URL: #432
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
  • Loading branch information
mattklein123 authored and maclover7 committed Jul 19, 2018
1 parent 5b76466 commit 25de6ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
19 changes: 7 additions & 12 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,21 +758,16 @@ size_t http_parser_execute (http_parser *parser,

case s_start_res:
{
if (ch == CR || ch == LF)
break;
parser->flags = 0;
parser->content_length = ULLONG_MAX;

switch (ch) {
case 'H':
UPDATE_STATE(s_res_H);
break;

case CR:
case LF:
break;

default:
SET_ERRNO(HPE_INVALID_CONSTANT);
goto error;
if (ch == 'H') {
UPDATE_STATE(s_res_H);
} else {
SET_ERRNO(HPE_INVALID_CONSTANT);
goto error;
}

CALLBACK_NOTIFY(message_begin);
Expand Down
2 changes: 2 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,7 @@ int
message_begin_cb (http_parser *p)
{
assert(p == &parser);
assert(!messages[num_messages].message_begin_cb_called);
messages[num_messages].message_begin_cb_called = TRUE;
return 0;
}
Expand Down Expand Up @@ -4189,6 +4190,7 @@ main (void)
test_simple_type("HTTP/11.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
test_simple_type("HTTP/1.01 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
test_simple_type("HTTP/1.1\t200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
test_simple_type("\rHTTP/1.1\t200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);

for (i = 0; i < ARRAY_SIZE(responses); i++) {
test_message(&responses[i]);
Expand Down

0 comments on commit 25de6ed

Please sign in to comment.