]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream: increase memcap on memory errors 6795/head
authorEric Leblond <el@stamus-networks.com>
Thu, 19 Aug 2021 09:22:06 +0000 (11:22 +0200)
committerJeff Lucovsky <jeff@lucovsky.org>
Sat, 15 Jan 2022 13:01:18 +0000 (08:01 -0500)
(cherry picked from commit c1bffa9545b8aa9d0fc64ac6511edd34919135d7)

src/stream-tcp-list.c

index 8c1d34042347dbd9f66fbea5b124e9c1dbe73695..ae1b23832362268451addf7b25fa76f4ea08eb14 100644 (file)
@@ -67,6 +67,10 @@ int TcpSegmentCompare(struct TcpSegment *a, struct TcpSegment *b)
  *  \param seg segment to store stream offset in
  *  \param data segment data after overlap handling (if any)
  *  \param data_len data length
+ *
+ *  \return 0 on success
+ *  \return -1 on memory allocation error
+ *  \return negative value on other errors
  */
 static inline int InsertSegmentDataCustom(TcpStream *stream, TcpSegment *seg, uint8_t *data, uint16_t data_len)
 {
@@ -91,11 +95,10 @@ static inline int InsertSegmentDataCustom(TcpStream *stream, TcpSegment *seg, ui
         SCReturnInt(0);
     }
 
-    if (StreamingBufferInsertAt(&stream->sb, &seg->sbseg,
-                data + data_offset,
-                data_len - data_offset,
-                stream_offset) != 0) {
-        SCReturnInt(-1);
+    int ret = StreamingBufferInsertAt(
+            &stream->sb, &seg->sbseg, data + data_offset, data_len - data_offset, stream_offset);
+    if (ret != 0) {
+        SCReturnInt(ret);
     }
 #ifdef DEBUG
     {
@@ -540,7 +543,11 @@ static int DoHandleData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
 
     /* insert the temp buffer now that we've (possibly) updated
      * it to account for the overlap policies */
-    if (InsertSegmentDataCustom(stream, handle, buf, p->payload_len) < 0) {
+    int res = InsertSegmentDataCustom(stream, handle, buf, p->payload_len);
+    if (res < 0) {
+        if (res == -1) {
+            StatsIncr(tv, ra_ctx->counter_tcp_segment_memcap);
+        }
         return -1;
     }
 
@@ -575,6 +582,9 @@ int StreamTcpReassembleInsertSegment(ThreadVars *tv, TcpReassemblyThreadCtx *ra_
         /* no overlap, straight data insert */
         int res = InsertSegmentDataCustom(stream, seg, pkt_data, pkt_datalen);
         if (res < 0) {
+            if (res == -1) {
+                StatsIncr(tv, ra_ctx->counter_tcp_segment_memcap);
+            }
             StatsIncr(tv, ra_ctx->counter_tcp_reass_data_normal_fail);
             StreamTcpRemoveSegmentFromStream(stream, seg);
             StreamTcpSegmentReturntoPool(seg);