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

Commit c7d4925

Browse files
committed
Fix bad pointer arithmetic
The bad arithmetic didn't result in wrong or insecure behavior (there were no out-of-bound accesses and forward progress was still being made because of the outer loop) but it did regress the performance of header field parsing rather massively. Taking the test suite as an example: the inner fast path loop was skipped over 4.4 million times, falling back to the outer slow path loop. After this commit that only happens about 2,000 times - a 2,200-fold reduction. Fixes: #473 PR-URL: #474 Reviewed-By: Fedor Indutny <[email protected]>
1 parent b6866a7 commit c7d4925

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

http_parser.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,9 +1257,9 @@ size_t http_parser_execute (http_parser *parser,
12571257

12581258
switch (parser->header_state) {
12591259
case h_general: {
1260-
size_t limit = data + len - p;
1261-
limit = MIN(limit, max_header_size);
1262-
while (p+1 < data + limit && TOKEN(p[1])) {
1260+
size_t left = data + len - p;
1261+
const char* pe = p + MIN(left, max_header_size);
1262+
while (p+1 < pe && TOKEN(p[1])) {
12631263
p++;
12641264
}
12651265
break;

0 commit comments

Comments
 (0)