Skip to content

Commit e3028fe

Browse files
committed
test: test for off-by-one bug when pausing parser
Pausing the parser from the on_headers_complete callback fails to account for the last byte of the headers. This bug has not yet been fixed, the test fails.
1 parent 99c0850 commit e3028fe

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test.c

+38
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,43 @@ test_message_pause (const struct message *msg)
26172617
parser_free();
26182618
}
26192619

2620+
static int
2621+
pause_after_headers_on_headers_complete(http_parser *parser)
2622+
{
2623+
http_parser_pause(parser, 1);
2624+
return 0;
2625+
}
2626+
2627+
static int
2628+
pause_after_headers_on_message_complete(http_parser *parser)
2629+
{
2630+
(void) parser;
2631+
assert(0);
2632+
abort();
2633+
return -1;
2634+
}
2635+
2636+
void
2637+
test_pause_after_headers(void)
2638+
{
2639+
const char input[] =
2640+
"GET / HTTP/1.1\r\n"
2641+
"Host: example.com\r\n"
2642+
"\r\n"
2643+
;
2644+
http_parser_settings settings;
2645+
http_parser parser;
2646+
size_t n;
2647+
2648+
memset(&settings, 0, sizeof(settings));
2649+
settings.on_headers_complete = pause_after_headers_on_headers_complete;
2650+
settings.on_message_complete = pause_after_headers_on_message_complete;
2651+
2652+
http_parser_init(&parser, HTTP_REQUEST);
2653+
n = http_parser_execute(&parser, &settings, input, sizeof(input) - 1);
2654+
assert(n == sizeof(input) - 1);
2655+
}
2656+
26202657
int
26212658
main (void)
26222659
{
@@ -2633,6 +2670,7 @@ main (void)
26332670
//// API
26342671
test_preserve_data();
26352672
test_parse_url();
2673+
test_pause_after_headers();
26362674

26372675
//// OVERFLOW CONDITIONS
26382676

0 commit comments

Comments
 (0)