]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/streaming-buffer: add extra safety check
authorPhilippe Antoine <pantoine@oisf.net>
Thu, 21 Nov 2024 14:20:44 +0000 (15:20 +0100)
committerVictor Julien <vjulien@oisf.net>
Thu, 12 Dec 2024 08:54:23 +0000 (09:54 +0100)
Ticket: 7393

Check if GrowRegionToSize is called with an argument
trying to shrink the region size, and if so do nothing,
ie do not try to shrink, and just return ok.

This way, we avoid a buffer overflow from memeset using an
unsigned having underflowed.

(cherry picked from commit 9a53ec43b13f0039a083950511a18bf6f408e432)

src/util-streaming-buffer.c

index 9dbaa5f33d86ed2a2b6acc6c44c023201a8c37fb..773a4e75727199440f6d873d5f30c5404270311a 100644 (file)
@@ -719,6 +719,10 @@ static inline int WARN_UNUSED GrowRegionToSize(StreamingBuffer *sb,
     /* try to grow in multiples of cfg->buf_size */
     const uint32_t grow = ToNextMultipleOf(size, cfg->buf_size);
     SCLogDebug("grow %u", grow);
+    if (grow <= region->buf_size) {
+        // do not try to shrink, and do not memset with diff having unsigned underflow
+        return SC_OK;
+    }
 
     void *ptr = REALLOC(cfg, region->buf, region->buf_size, grow);
     if (ptr == NULL) {