From ceeaa8db5657854cf28711fe6708d32f048f1a7b Mon Sep 17 00:00:00 2001 From: Masakazu Kitajo Date: Tue, 22 Dec 2015 11:01:33 +0900 Subject: [PATCH 1/2] TS-4097: Encode empty string properly with HPACK --- proxy/http2/HPACK.cc | 8 +++++--- proxy/http2/RegressionHPACK.cc | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/proxy/http2/HPACK.cc b/proxy/http2/HPACK.cc index 51b9a2fb93d..b54d9235e09 100644 --- a/proxy/http2/HPACK.cc +++ b/proxy/http2/HPACK.cc @@ -338,7 +338,7 @@ encode_string(uint8_t *buf_start, const uint8_t *buf_end, const char *value, siz // TODO Choose whether to use Huffman encoding wisely - if (use_huffman) { + if (use_huffman && value_len) { data = static_cast(ats_malloc(value_len * 4)); if (data == NULL) return -1; @@ -369,8 +369,10 @@ encode_string(uint8_t *buf_start, const uint8_t *buf_end, const char *value, siz } // Value - memcpy(p, data, data_len); - p += data_len; + if (data_len) { + memcpy(p, data, data_len); + p += data_len; + } if (use_huffman) { ats_free(data); diff --git a/proxy/http2/RegressionHPACK.cc b/proxy/http2/RegressionHPACK.cc index 5ceebc84703..a2d924f10c3 100644 --- a/proxy/http2/RegressionHPACK.cc +++ b/proxy/http2/RegressionHPACK.cc @@ -53,9 +53,15 @@ const static struct { uint32_t raw_string_len; uint8_t *encoded_field; int encoded_field_len; -} string_test_case[] = {{(char *)"custom-key", 10, (uint8_t *) "\xA" +} string_test_case[] = {{(char *)"", 0, (uint8_t *) "\x0" + "", + 1}, + {(char *)"custom-key", 10, (uint8_t *) "\xA" "custom-key", 11}, + {(char *)"", 0, (uint8_t *) "\x80" + "", + 1}, {(char *)"custom-key", 10, (uint8_t *) "\x88" "\x25\xa8\x49\xe9\x5b\xa9\x7d\x7f", 9}}; @@ -232,7 +238,7 @@ REGRESSION_TEST(HPACK_EncodeString)(RegressionTest *t, int, int *pstatus) int len; // FIXME Current encoder support only huffman conding. - for (unsigned int i = 1; i < 2; i++) { + for (unsigned int i = 2; i < sizeof(string_test_case) / sizeof(string_test_case[0]); i++) { memset(buf, 0, BUFSIZE_FOR_REGRESSION_TEST); len = encode_string(buf, buf + BUFSIZE_FOR_REGRESSION_TEST, string_test_case[i].raw_string, string_test_case[i].raw_string_len); From 280172922ce4503f0fafbbe4e138cf469720fa44 Mon Sep 17 00:00:00 2001 From: Masakazu Kitajo Date: Wed, 23 Dec 2015 20:37:08 +0900 Subject: [PATCH 2/2] TS-4097: Fix use of wrong variable in regression test --- proxy/http2/RegressionHPACK.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/http2/RegressionHPACK.cc b/proxy/http2/RegressionHPACK.cc index a2d924f10c3..fe5ee71f397 100644 --- a/proxy/http2/RegressionHPACK.cc +++ b/proxy/http2/RegressionHPACK.cc @@ -244,7 +244,7 @@ REGRESSION_TEST(HPACK_EncodeString)(RegressionTest *t, int, int *pstatus) len = encode_string(buf, buf + BUFSIZE_FOR_REGRESSION_TEST, string_test_case[i].raw_string, string_test_case[i].raw_string_len); box.check(len == string_test_case[i].encoded_field_len, "encoded length was %d, expecting %d", len, - integer_test_case[i].encoded_field_len); + string_test_case[i].encoded_field_len); box.check(len > 0 && memcmp(buf, string_test_case[i].encoded_field, len) == 0, "encoded string was invalid"); } }