Skip to content

Commit

Permalink
Fix #768: Add check for 'signed int' overflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksostapenko committed Aug 23, 2017
1 parent 9df1d21 commit 576dd0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tempesta_fw/http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,13 @@ parse_int_hex(unsigned char *data, size_t len, unsigned long *acc, unsigned shor
unsigned char *p;

for (p = data; p - data < len; ++p) {
if (unlikely(IS_CRLF(*p) || (*p == ';')))
if (unlikely(IS_CRLF(*p) || (*p == ';'))) {
if (unlikely(*acc > INT_MAX))
return CSTR_BADLEN;
return p - data;
}
if (unlikely(!isxdigit(*p)))
return CSTR_NEQ;
if (unlikely(*acc > (UINT_MAX - 16) / 16))
return CSTR_BADLEN;
if (unlikely(*cnt >= (sizeof(int) * 2)))
return CSTR_BADLEN;
*acc = (*acc << 4) + (*p & 0xf) + (*p >> 6) * 9;
Expand Down
9 changes: 9 additions & 0 deletions tempesta_fw/t/unit/test_http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,15 @@ TEST(http_parser, chunk_size)
"000000000\r\n"
"\r\n");

EXPECT_BLOCK_REQ("POST / HTTP/1.1\r\n"
"Host:\r\n"
"Transfer-Encoding: chunked\r\n"
"\r\n"
"80000000\r\n"
"abcdefg\r\n"
"0\r\n"
"\r\n");

FOR_REQ("POST / HTTP/1.1\r\n"
"Host:\r\n"
"Transfer-Encoding: chunked\r\n"
Expand Down

0 comments on commit 576dd0e

Please sign in to comment.