]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
streaming/buffer: fix buf_offset getting out of sync
authorVictor Julien <vjulien@oisf.net>
Wed, 7 Jun 2023 05:38:52 +0000 (07:38 +0200)
committerVictor Julien <vjulien@oisf.net>
Wed, 7 Jun 2023 19:45:30 +0000 (21:45 +0200)
During consolidation of regions, buf_offset could get out of sync if
the region was grown on the left side.

To fix, reset it and let "sbb slide" logic correct it.

Bug: #6117.

src/util-streaming-buffer.c

index 39147ebc1e94301d37cab36730dda6cc2ef621f5..911504a1b322d79eb8759c36ab922f1f05f26028 100644 (file)
@@ -1201,7 +1201,11 @@ static StreamingBufferRegion *BufferInsertAtRegionConsolidate(StreamingBuffer *s
     DEBUG_VALIDATE_BUG_ON(dst_size != dst->buf_size);
     if (dst_copy_offset != 0)
         memmove(dst->buf + dst_copy_offset, dst->buf, old_size);
-    dst->stream_offset = dst_offset;
+    if (dst_offset != dst->stream_offset) {
+        dst->stream_offset = dst_offset;
+        // buf_offset no longer valid, reset.
+        dst->buf_offset = 0;
+    }
 
     uint32_t new_offset = src_start->buf_offset;
     if (data_offset == src_start->stream_offset + src_start->buf_offset) {