]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2990 in SNORT/snort3 from ~KATHARVE/snort3:h2i_partial_buffer_fix...
authorTom Peters (thopeter) <thopeter@cisco.com>
Fri, 23 Jul 2021 20:30:30 +0000 (20:30 +0000)
committerTom Peters (thopeter) <thopeter@cisco.com>
Fri, 23 Jul 2021 20:30:30 +0000 (20:30 +0000)
Squashed commit of the following:

commit 288ed022ae6a31f5bb2b98e84b8a42cc2bff7b5e
Author: Katura Harvey <katharve@cisco.com>
Date:   Tue Jul 20 14:33:28 2021 -0400

    http_inspect: don't allocate 0-length partial inspection buffer

src/service_inspectors/http_inspect/http_stream_splitter_reassemble.cc

index 213288f4b1e0914190cd4fb9daabb9b804221220..8ba5be460847cc30ffb4c8afa87cb417d6ee1fe0 100644 (file)
@@ -410,17 +410,22 @@ const StreamBuffer HttpStreamSplitter::reassemble(Flow* flow, unsigned total,
         uint32_t& running_total = session_data->running_total[source_id];
         assert(running_total == total);
         running_total = 0;
-        const uint16_t buf_size =
+        const uint32_t buf_size =
             session_data->section_offset[source_id] - session_data->num_excess[source_id];
 
         if (session_data->partial_flush[source_id])
         {
-            // Store the data from a partial flush for reuse
-            partial_buffer = new uint8_t[buf_size];
-            memcpy(partial_buffer, buffer, buf_size);
-            partial_buffer_length = buf_size;
+            // It's possible we're doing a partial flush but there is no actual data to flush after
+            // decompression.
+            if (buf_size > 0)
+            {
+                // Store the data from a partial flush for reuse
+                partial_buffer = new uint8_t[buf_size];
+                memcpy(partial_buffer, buffer, buf_size);
+                partial_buffer_length = buf_size;
+                session_data->update_allocations(partial_buffer_length);
+            }
             partial_raw_bytes += total;
-            session_data->update_allocations(partial_buffer_length);
         }
         else
             partial_raw_bytes = 0;