From: Philippe Antoine Date: Thu, 21 Nov 2024 14:17:21 +0000 (+0100) Subject: util/streaming-buffer: check need to grow region X-Git-Tag: suricata-7.0.8~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=949bfeca0e5f92212dc3d79f4a87c7c482d376aa;p=thirdparty%2Fsuricata.git util/streaming-buffer: check need to grow region 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. (cherry picked from commit 8900041405dbb5f9584edae994af2100733fb4be) --- diff --git a/src/util-streaming-buffer.c b/src/util-streaming-buffer.c index b3f5d5d753..9dbaa5f33d 100644 --- a/src/util-streaming-buffer.c +++ b/src/util-streaming-buffer.c @@ -940,9 +940,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);