src: partially revert 959f4cb to fix nread value

With 959f4cb on reexecution - header byte was accounted twice, leading
to the incorrect `parser->nread` value.

Fix: #220
PR-URL: https://github.com/joyent/http-parser/pull/221
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
make-http-max-header-size-gyp-configurable
Fedor Indutny 10 years ago
parent 7ba312397c
commit 7ecf775d71

@ -64,8 +64,7 @@ do { \
return (V); \ return (V); \
} while (0); } while (0);
#define REEXECUTE() \ #define REEXECUTE() \
--p; \ goto reexecute; \
break;
#ifdef __GNUC__ #ifdef __GNUC__
@ -697,6 +696,7 @@ size_t http_parser_execute (http_parser *parser,
if (PARSING_HEADER(CURRENT_STATE())) if (PARSING_HEADER(CURRENT_STATE()))
COUNT_HEADER_SIZE(1); COUNT_HEADER_SIZE(1);
reexecute:
switch (CURRENT_STATE()) { switch (CURRENT_STATE()) {
case s_dead: case s_dead:

@ -3044,6 +3044,22 @@ test_header_overflow_error (int req)
abort(); abort();
} }
void
test_header_nread_value ()
{
http_parser parser;
http_parser_init(&parser, HTTP_REQUEST);
size_t parsed;
const char *buf;
buf = "GET / HTTP/1.1\r\nheader: value\nhdr: value\r\n";
parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
assert(parsed == strlen(buf));
assert(parser.nread == strlen(buf));
}
static void static void
test_content_length_overflow (const char *buf, size_t buflen, int expect_ok) test_content_length_overflow (const char *buf, size_t buflen, int expect_ok)
{ {
@ -3410,6 +3426,9 @@ main (void)
test_parse_url(); test_parse_url();
test_method_str(); test_method_str();
//// NREAD
test_header_nread_value();
//// OVERFLOW CONDITIONS //// OVERFLOW CONDITIONS
test_header_overflow_error(HTTP_REQUEST); test_header_overflow_error(HTTP_REQUEST);

Loading…
Cancel
Save