From 7ecf775d71337927acbacf64e4267175c5a51187 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 19 Feb 2015 12:31:16 +0100 Subject: [PATCH] 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 --- http_parser.c | 4 ++-- test.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/http_parser.c b/http_parser.c index ebfdbf6..aa6310f 100644 --- a/http_parser.c +++ b/http_parser.c @@ -64,8 +64,7 @@ do { \ return (V); \ } while (0); #define REEXECUTE() \ - --p; \ - break; + goto reexecute; \ #ifdef __GNUC__ @@ -697,6 +696,7 @@ size_t http_parser_execute (http_parser *parser, if (PARSING_HEADER(CURRENT_STATE())) COUNT_HEADER_SIZE(1); +reexecute: switch (CURRENT_STATE()) { case s_dead: diff --git a/test.c b/test.c index aae0f73..58c1955 100644 --- a/test.c +++ b/test.c @@ -3044,6 +3044,22 @@ test_header_overflow_error (int req) 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 test_content_length_overflow (const char *buf, size_t buflen, int expect_ok) { @@ -3410,6 +3426,9 @@ main (void) test_parse_url(); test_method_str(); + //// NREAD + test_header_nread_value(); + //// OVERFLOW CONDITIONS test_header_overflow_error(HTTP_REQUEST);