Strictly check occurrence of dynamic table size update

RFC 7541 requires that dynamic table size update must occur at the
beginning of the first header block, and is signaled as SETTINGS
acknowledgement.  This commit checks these conditions.  If dynamic
table size update appears other than the beginning of the first header
block, it is treated as error.  If SETTINGS ACK is received, and next
HEADERS header block does not have dynamic table size update, it is
treated as error.
This commit is contained in:
Tatsuhiro Tsujikawa
2015-07-22 00:11:23 +09:00
parent 18234b8741
commit f3288092e8
6 changed files with 95 additions and 2 deletions

View File

@@ -326,6 +326,10 @@ int main(int argc _U_, char *argv[] _U_) {
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_inflate_expect_table_size_update",
test_nghttp2_hd_inflate_expect_table_size_update) ||
!CU_add_test(pSuite, "hd_inflate_unexpected_table_size_update",
test_nghttp2_hd_inflate_unexpected_table_size_update) ||
!CU_add_test(pSuite, "hd_ringbuf_reserve",
test_nghttp2_hd_ringbuf_reserve) ||
!CU_add_test(pSuite, "hd_change_table_size",

View File

@@ -540,6 +540,54 @@ void test_nghttp2_hd_inflate_zero_length_huffman(void) {
nghttp2_hd_inflate_free(&inflater);
}
void test_nghttp2_hd_inflate_expect_table_size_update(void) {
nghttp2_hd_inflater inflater;
nghttp2_bufs bufs;
nghttp2_mem *mem;
/* Indexed Header: :method: GET */
uint8_t data[] = {0x82};
nva_out out;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
nva_out_init(&out);
nghttp2_bufs_add(&bufs, data, sizeof(data));
nghttp2_hd_inflate_init(&inflater, mem);
/* This will make inflater require table size update in the next
inflation. */
nghttp2_hd_inflate_change_table_size(&inflater, 4096);
CU_ASSERT(NGHTTP2_ERR_HEADER_COMP ==
inflate_hd(&inflater, &out, &bufs, 0, mem));
nva_out_reset(&out, mem);
nghttp2_bufs_free(&bufs);
nghttp2_hd_inflate_free(&inflater);
}
void test_nghttp2_hd_inflate_unexpected_table_size_update(void) {
nghttp2_hd_inflater inflater;
nghttp2_bufs bufs;
nghttp2_mem *mem;
/* Indexed Header: :method: GET, followed by table size update.
This violates RFC 7541. */
uint8_t data[] = {0x82, 0x20};
nva_out out;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
nva_out_init(&out);
nghttp2_bufs_add(&bufs, data, sizeof(data));
nghttp2_hd_inflate_init(&inflater, mem);
CU_ASSERT(NGHTTP2_ERR_HEADER_COMP ==
inflate_hd(&inflater, &out, &bufs, 0, mem));
nva_out_reset(&out, mem);
nghttp2_bufs_free(&bufs);
nghttp2_hd_inflate_free(&inflater);
}
void test_nghttp2_hd_ringbuf_reserve(void) {
nghttp2_hd_deflater deflater;
nghttp2_hd_inflater inflater;

View File

@@ -35,6 +35,8 @@ 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_inflate_expect_table_size_update(void);
void test_nghttp2_hd_inflate_unexpected_table_size_update(void);
void test_nghttp2_hd_ringbuf_reserve(void);
void test_nghttp2_hd_change_table_size(void);
void test_nghttp2_hd_deflate_inflate(void);