]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream: update insert error checking
authorVictor Julien <vjulien@oisf.net>
Thu, 4 May 2023 13:27:03 +0000 (15:27 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 13 Jun 2023 11:12:14 +0000 (13:12 +0200)
src/decode-events.c
src/decode-events.h
src/stream-tcp-list.c

index 22242e70492b3ac48c07b1e3f71fd6bc84922301..207de286f6ef862e48de24550f2e027818b2099d 100644 (file)
@@ -856,6 +856,18 @@ const struct DecodeEvents_ DEvents[] = {
             "stream.reassembly_depth_reached",
             STREAM_REASSEMBLY_DEPTH_REACHED,
     },
+    {
+            "stream.reassembly_insert_memcap",
+            STREAM_REASSEMBLY_INSERT_MEMCAP,
+    },
+    {
+            "stream.reassembly_insert_limit",
+            STREAM_REASSEMBLY_INSERT_LIMIT,
+    },
+    {
+            "stream.reassembly_insert_invalid",
+            STREAM_REASSEMBLY_INSERT_INVALID,
+    },
 
     { NULL, 0 },
 };
index 6e2d638c3c1cba92424f3f7e53d4d9f4020fc91f..451482403cb6a733534ea0743b30683be38ba430 100644 (file)
@@ -292,6 +292,9 @@ enum {
     STREAM_REASSEMBLY_SEQ_GAP,
     STREAM_REASSEMBLY_OVERLAP_DIFFERENT_DATA,
     STREAM_REASSEMBLY_DEPTH_REACHED,
+    STREAM_REASSEMBLY_INSERT_MEMCAP,
+    STREAM_REASSEMBLY_INSERT_LIMIT,
+    STREAM_REASSEMBLY_INSERT_INVALID,
 
     /* should always be last! */
     DECODE_EVENT_MAX,
index 4013bd57f9bc0b76aea952e6009c890874deaeaa..164825440f0c4335aecbf31255b583e063d176a0 100644 (file)
@@ -98,11 +98,8 @@ static inline int InsertSegmentDataCustom(TcpStream *stream, TcpSegment *seg, ui
 
     int ret = StreamingBufferInsertAt(&stream->sb, &stream_config.sbcnf, &seg->sbseg,
             data + data_offset, data_len - data_offset, stream_offset);
-    if (ret != 0) {
-        /* StreamingBufferInsertAt can return -2 only if the offset is wrong, which should be
-         * impossible in this path. */
-        DEBUG_VALIDATE_BUG_ON(ret != -1);
-        SCReturnInt(SC_ENOMEM);
+    if (ret != SC_OK) {
+        SCReturnInt(ret);
     }
 #ifdef DEBUG
     {
@@ -550,6 +547,13 @@ static int DoHandleData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
     if (res != SC_OK) {
         if (res == SC_ENOMEM) {
             StatsIncr(tv, ra_ctx->counter_tcp_segment_memcap);
+            StreamTcpSetEvent(p, STREAM_REASSEMBLY_INSERT_MEMCAP);
+        } else if (res == SC_ELIMIT) {
+            StreamTcpSetEvent(p, STREAM_REASSEMBLY_INSERT_LIMIT);
+        } else if (res == SC_EINVAL) {
+            StreamTcpSetEvent(p, STREAM_REASSEMBLY_INSERT_INVALID);
+        } else {
+            DEBUG_VALIDATE_BUG_ON(1);
         }
         return -1;
     }