]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1942 in SNORT/snort3 from ~DERAMADA/snort3:h2i_new_tests to master
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Fri, 17 Jan 2020 14:48:09 +0000 (14:48 +0000)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Fri, 17 Jan 2020 14:48:09 +0000 (14:48 +0000)
Squashed commit of the following:

commit 4ff7df9bd99779dc9fb82e72eaaaf548624811ef
Author: deramada <deramada@cisco.com>
Date:   Tue Jan 14 10:41:19 2020 -0500

    http2_inspect: fix string decode error

src/service_inspectors/http2_inspect/http2_hpack_string_decode.cc
src/service_inspectors/http2_inspect/test/http2_hpack_string_decode_test.cc

index d772154475f3e9573ac63abcd08dafa0836a96eb..ff4a63e6021f8bce043ee215253772487c223253 100644 (file)
@@ -202,7 +202,9 @@ bool Http2HpackStringDecode::get_huffman_string(const uint8_t* in_buff, const ui
     // Tail needs 1 last lookup in case the leftover is big enough for a match.
     // Make sure match length <= available length
     uint8_t leftover_len = 8 - cur_bit;
-    uint8_t old_result = result.len;
+    uint8_t old_result_len = result.len;
+    HuffmanState old_result_state = result.state;
+
     if (another_search && (leftover_len >= min_decode_len[state]))
     {
         result = huffman_decode[state][byte];
@@ -212,7 +214,13 @@ bool Http2HpackStringDecode::get_huffman_string(const uint8_t* in_buff, const ui
             byte = (byte << result.len) | (((uint16_t)1 << result.len) - 1);
         }
         else
-            result.len = old_result;
+        {
+            // Use leftover bits for padding check if previous lookup was a match
+            if (old_result_state == HUFFMAN_MATCH)
+                result.len = leftover_len;
+            else
+                result.len = old_result_len;
+        }
     }
 
     // Padding check
index 083b15dd3c586ceb87cd790af3c30d2d72bb2078..0a710b4e581f7cdf0be6942163fe9c7a1bd95dba 100644 (file)
@@ -582,6 +582,21 @@ TEST(http2_hpack_string_decode_success, huffman_decoding_all_possible_symbols_he
     CHECK(memcmp(res, expected, 16) == 0);
 }
 
+TEST(http2_hpack_string_decode_success, huffman_decoding_tail_lookup_unsucessful)
+{
+    // tail lookup unsuccessful after successful previous match
+    // decodes to 9D
+    uint8_t buf[3] = {0x82, 0x7E, 0xFF};
+    // decode
+    uint32_t bytes_processed = 0, bytes_written = 0;
+    uint8_t res[3];
+    bool success = decode->translate(buf, 3, bytes_processed, res, 3, bytes_written, &events, &inf);
+    // check results
+    CHECK(success == true);
+    CHECK(bytes_processed == 3);
+    CHECK(bytes_written == 2);
+}
+
 //
 // The following tests should trigger infractions/events
 //