util/streaming-buffer: add extra safety check

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.
pull/12272/head
Philippe Antoine 1 year ago committed by Victor Julien
parent 8900041405
commit 9a53ec43b1

@ -717,6 +717,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) {

Loading…
Cancel
Save