]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/streaming-buffer: check need to grow region
authorPhilippe Antoine <pantoine@oisf.net>
Thu, 21 Nov 2024 14:17:21 +0000 (15:17 +0100)
committerVictor Julien <vjulien@oisf.net>
Wed, 11 Dec 2024 05:49:35 +0000 (06:49 +0100)
Ticket: 7393

As it was possible before earlier patches to get here
with mem_size lesser than start->buf_size,
which caused then an unsigned underflow and a buffer overflow.

src/util-streaming-buffer.c

index aea6934634dea448b8491e0de545855b7be21cf4..a62bbf89567743ef385bcc1a58424100c306ab58 100644 (file)
@@ -938,9 +938,13 @@ static inline void StreamingBufferSlideToOffsetWithRegions(
                     goto done;
                 } else {
                     /* using "main", expand to include "next" */
-                    if (GrowRegionToSize(sb, cfg, start, mem_size) != 0) {
-                        new_mem_size = new_data_size;
-                        goto just_main;
+                    if (mem_size > start->buf_size) {
+                        // Check that start->buf_size is actually not big enough
+                        // As mem_size computation and earlier checks do not make it clear.
+                        if (GrowRegionToSize(sb, cfg, start, mem_size) != 0) {
+                            new_mem_size = new_data_size;
+                            goto just_main;
+                        }
                     }
                     SCLogDebug("start->buf now size %u", mem_size);