From 0097de5895e4ec79e0191682d600a8e450051cb6 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Sat, 29 Nov 2014 00:11:37 +0300 Subject: [PATCH] src: use memchr() in h_general header value --- http_parser.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/http_parser.c b/http_parser.c index 263eaeb..bb99d76 100644 --- a/http_parser.c +++ b/http_parser.c @@ -1516,16 +1516,29 @@ size_t http_parser_execute (http_parser *parser, switch (h_state) { case h_general: - for (; p != data + len; p++) { - ch = *p; - if (ch == CR || ch == LF) { - --p; - break; - } + { + const char* p_cr; + const char* p_lf; + size_t limit = data + len - p; + + limit = MIN(limit, HTTP_MAX_HEADER_SIZE); + + p_cr = memchr(p, CR, limit); + p_lf = memchr(p, LF, limit); + if (p_cr != NULL) { + if (p_lf != NULL && p_cr >= p_lf) + p = p_lf; + else + p = p_cr; + } else if (p_lf != NULL) { + p = p_lf; + } else { + p = data + len; } - if (p == data + len) - --p; + --p; + break; + } case h_connection: case h_transfer_encoding: