fix content-length and chunk-size overflow test

The overflow check didn't work for all possible inputs.
make-http-max-header-size-gyp-configurable
Alexis Campailla 11 years ago committed by Fedor Indutny
parent 42d6541577
commit a252d4eebc

@ -1509,8 +1509,8 @@ size_t http_parser_execute (http_parser *parser,
t *= 10; t *= 10;
t += ch - '0'; t += ch - '0';
/* Overflow? */ /* Overflow? Test against a conservative limit for simplicity. */
if (t < parser->content_length || t == ULLONG_MAX) { if ((ULLONG_MAX - 10) / 10 < parser->content_length) {
SET_ERRNO(HPE_INVALID_CONTENT_LENGTH); SET_ERRNO(HPE_INVALID_CONTENT_LENGTH);
goto error; goto error;
} }
@ -1782,8 +1782,8 @@ size_t http_parser_execute (http_parser *parser,
t *= 16; t *= 16;
t += unhex_val; t += unhex_val;
/* Overflow? */ /* Overflow? Test against a conservative limit for simplicity. */
if (t < parser->content_length || t == ULLONG_MAX) { if ((ULLONG_MAX - 16) / 16 < parser->content_length) {
SET_ERRNO(HPE_INVALID_CONTENT_LENGTH); SET_ERRNO(HPE_INVALID_CONTENT_LENGTH);
goto error; goto error;
} }

@ -2938,7 +2938,7 @@ test_header_content_length_overflow_error (void)
"HTTP/1.1 200 OK\r\n" \ "HTTP/1.1 200 OK\r\n" \
"Content-Length: " #size "\r\n" \ "Content-Length: " #size "\r\n" \
"\r\n" "\r\n"
const char a[] = X(18446744073709551614); /* 2^64-2 */ const char a[] = X(1844674407370955160); /* 2^64 / 10 - 1 */
const char b[] = X(18446744073709551615); /* 2^64-1 */ const char b[] = X(18446744073709551615); /* 2^64-1 */
const char c[] = X(18446744073709551616); /* 2^64 */ const char c[] = X(18446744073709551616); /* 2^64 */
#undef X #undef X
@ -2956,7 +2956,7 @@ test_chunk_content_length_overflow_error (void)
"\r\n" \ "\r\n" \
#size "\r\n" \ #size "\r\n" \
"..." "..."
const char a[] = X(FFFFFFFFFFFFFFFE); /* 2^64-2 */ const char a[] = X(FFFFFFFFFFFFFFE); /* 2^64 / 16 - 1 */
const char b[] = X(FFFFFFFFFFFFFFFF); /* 2^64-1 */ const char b[] = X(FFFFFFFFFFFFFFFF); /* 2^64-1 */
const char c[] = X(10000000000000000); /* 2^64 */ const char c[] = X(10000000000000000); /* 2^64 */
#undef X #undef X

Loading…
Cancel
Save