nghttp2_hd: Don't malloc if huffman encoded string has 0 length

This commit is contained in:
Tatsuhiro Tsujikawa 2013-12-19 23:19:14 +09:00
parent 7a9eca1f7d
commit 7c4dbb6ffc
4 changed files with 34 additions and 1 deletions

View File

@ -1240,7 +1240,12 @@ static int inflater_post_process_hd_entry(nghttp2_hd_context *inflater,
static ssize_t inflate_decode(uint8_t **dest_ptr, uint8_t *in, size_t inlen,
nghttp2_hd_side side)
{
ssize_t declen = nghttp2_hd_huff_decode_count(in, inlen, side);
ssize_t declen;
if(inlen == 0) {
*dest_ptr = NULL;
return 0;
}
declen = nghttp2_hd_huff_decode_count(in, inlen, side);
if(declen == -1) {
return NGHTTP2_ERR_HEADER_COMP;
}

View File

@ -240,6 +240,8 @@ int main(int argc, char* argv[])
test_nghttp2_hd_inflate_newname_inc) ||
!CU_add_test(pSuite, "hd_inflate_clearall_inc",
test_nghttp2_hd_inflate_clearall_inc) ||
!CU_add_test(pSuite, "hd_inflate_zero_length_huffman",
test_nghttp2_hd_inflate_zero_length_huffman) ||
!CU_add_test(pSuite, "hd_change_table_size",
test_nghttp2_hd_change_table_size) ||
!CU_add_test(pSuite, "hd_deflate_inflate",

View File

@ -689,6 +689,31 @@ void test_nghttp2_hd_inflate_clearall_inc(void)
nghttp2_hd_inflate_free(&inflater);
}
void test_nghttp2_hd_inflate_zero_length_huffman(void)
{
nghttp2_hd_context inflater;
uint8_t buf[4];
nghttp2_nv *resnva;
/* Literal header without indexing - new name */
buf[0] = 0x40;
buf[1] = 1;
buf[2] = 'x';
buf[3] = 0x80;
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST);
CU_ASSERT(1 == nghttp2_hd_inflate_hd(&inflater, &resnva, buf, 4));
CU_ASSERT(1 == resnva[0].namelen);
CU_ASSERT('x' == resnva[0].name[0]);
CU_ASSERT(NULL == resnva[0].value);
CU_ASSERT(0 == resnva[0].valuelen);
nghttp2_nv_array_del(resnva);
nghttp2_hd_end_headers(&inflater);
nghttp2_hd_inflate_free(&inflater);
}
void test_nghttp2_hd_change_table_size(void)
{
nghttp2_hd_context deflater;

View File

@ -36,6 +36,7 @@ void test_nghttp2_hd_inflate_indname_inc_eviction(void);
void test_nghttp2_hd_inflate_newname_noinc(void);
void test_nghttp2_hd_inflate_newname_inc(void);
void test_nghttp2_hd_inflate_clearall_inc(void);
void test_nghttp2_hd_inflate_zero_length_huffman(void);
void test_nghttp2_hd_change_table_size(void);
void test_nghttp2_hd_deflate_inflate(void);