|
25 | 25 | #include <string.h>
|
26 | 26 | #include <limits.h>
|
27 | 27 |
|
| 28 | +static uint64_t max_header_size = HTTP_MAX_HEADER_SIZE; |
| 29 | + |
28 | 30 | #ifndef ULLONG_MAX
|
29 | 31 | # define ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */
|
30 | 32 | #endif
|
@@ -139,20 +141,20 @@ do { \
|
139 | 141 | } while (0)
|
140 | 142 |
|
141 | 143 | /* Don't allow the total size of the HTTP headers (including the status
|
142 |
| - * line) to exceed HTTP_MAX_HEADER_SIZE. This check is here to protect |
| 144 | + * line) to exceed max_header_size. This check is here to protect |
143 | 145 | * embedders against denial-of-service attacks where the attacker feeds
|
144 | 146 | * us a never-ending header that the embedder keeps buffering.
|
145 | 147 | *
|
146 | 148 | * This check is arguably the responsibility of embedders but we're doing
|
147 | 149 | * it on the embedder's behalf because most won't bother and this way we
|
148 |
| - * make the web a little safer. HTTP_MAX_HEADER_SIZE is still far bigger |
| 150 | + * make the web a little safer. max_header_size is still far bigger |
149 | 151 | * than any reasonable request or response so this should never affect
|
150 | 152 | * day-to-day operation.
|
151 | 153 | */
|
152 | 154 | #define COUNT_HEADER_SIZE(V) \
|
153 | 155 | do { \
|
154 | 156 | nread += (V); \
|
155 |
| - if (UNLIKELY(nread > (HTTP_MAX_HEADER_SIZE))) { \ |
| 157 | + if (UNLIKELY(nread > max_header_size)) { \ |
156 | 158 | SET_ERRNO(HPE_HEADER_OVERFLOW); \
|
157 | 159 | goto error; \
|
158 | 160 | } \
|
@@ -1256,7 +1258,7 @@ size_t http_parser_execute (http_parser *parser,
|
1256 | 1258 | switch (parser->header_state) {
|
1257 | 1259 | case h_general: {
|
1258 | 1260 | size_t limit = data + len - p;
|
1259 |
| - limit = MIN(limit, HTTP_MAX_HEADER_SIZE); |
| 1261 | + limit = MIN(limit, max_header_size); |
1260 | 1262 | while (p+1 < data + limit && TOKEN(p[1])) {
|
1261 | 1263 | p++;
|
1262 | 1264 | }
|
@@ -1494,7 +1496,7 @@ size_t http_parser_execute (http_parser *parser,
|
1494 | 1496 | const char* p_lf;
|
1495 | 1497 | size_t limit = data + len - p;
|
1496 | 1498 |
|
1497 |
| - limit = MIN(limit, HTTP_MAX_HEADER_SIZE); |
| 1499 | + limit = MIN(limit, max_header_size); |
1498 | 1500 |
|
1499 | 1501 | p_cr = (const char*) memchr(p, CR, limit);
|
1500 | 1502 | p_lf = (const char*) memchr(p, LF, limit);
|
@@ -2478,3 +2480,8 @@ http_parser_version(void) {
|
2478 | 2480 | HTTP_PARSER_VERSION_MINOR * 0x00100 |
|
2479 | 2481 | HTTP_PARSER_VERSION_PATCH * 0x00001;
|
2480 | 2482 | }
|
| 2483 | + |
| 2484 | +void |
| 2485 | +http_parser_set_max_header_size(uint64_t size) { |
| 2486 | + max_header_size = size; |
| 2487 | +} |
0 commit comments