You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2015/12/30 14:43:23 UTC

trafficserver git commit: TS-4097: Encode empty string properly with HPACK

Repository: trafficserver
Updated Branches:
  refs/heads/master a94590e43 -> 413dd51d5


TS-4097: Encode empty string properly with HPACK

This closes #395.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/413dd51d
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/413dd51d
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/413dd51d

Branch: refs/heads/master
Commit: 413dd51d5dc17bf388805071efdb8f882014b847
Parents: a94590e
Author: Masakazu Kitajo <ma...@apache.org>
Authored: Tue Dec 22 11:01:33 2015 +0900
Committer: Masakazu Kitajo <ma...@apache.org>
Committed: Wed Dec 30 22:02:03 2015 +0900

----------------------------------------------------------------------
 proxy/http2/HPACK.cc           |  8 +++++---
 proxy/http2/RegressionHPACK.cc | 12 +++++++++---
 2 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/413dd51d/proxy/http2/HPACK.cc
----------------------------------------------------------------------
diff --git a/proxy/http2/HPACK.cc b/proxy/http2/HPACK.cc
index 51b9a2f..b54d923 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<char *>(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);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/413dd51d/proxy/http2/RegressionHPACK.cc
----------------------------------------------------------------------
diff --git a/proxy/http2/RegressionHPACK.cc b/proxy/http2/RegressionHPACK.cc
index 5ceebc8..fe5ee71 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,13 +238,13 @@ 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);
 
     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");
   }
 }