]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
protodetect: handle all gaps, even when depth is reached
authorPhilippe Antoine <contact@catenacyber.fr>
Mon, 23 Aug 2021 14:31:42 +0000 (16:31 +0200)
committerJeff Lucovsky <jeff@lucovsky.org>
Wed, 6 Oct 2021 12:34:02 +0000 (08:34 -0400)
(cherry picked from commit 527415dba08f6f2af7fb93fdef19e3029cef88bd)

src/app-layer.c
src/stream-tcp-reassemble.c

index 6430128370c470f4f0073af27f1405b7cf7ef053..5a4f5dc94863d34400c4f2af69af5526b68ecd89 100644 (file)
@@ -325,6 +325,7 @@ static int TCPProtoDetect(ThreadVars *tv,
 #endif
 
     bool reverse_flow = false;
+    DEBUG_VALIDATE_BUG_ON(data == NULL && data_len > 0);
     PACKET_PROFILING_APP_PD_START(app_tctx);
     *alproto = AppLayerProtoDetectGetProto(app_tctx->alpd_tctx,
             f, data, data_len,
index 62023ea71a4de8b98ae171352be6cff66813818c..514e906ed4150360b7e16326952da4041281bd38 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2016 Open Information Security Foundation
+/* Copyright (C) 2007-2021 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -1029,6 +1029,7 @@ static int ReassembleUpdateAppLayer (ThreadVars *tv,
     uint32_t mydata_len;
 
     while (1) {
+        const uint8_t flags = StreamGetAppLayerFlags(ssn, *stream, p);
         GetAppBuffer(*stream, &mydata, &mydata_len, app_progress);
         DEBUG_VALIDATE_BUG_ON(mydata_len > (uint32_t)INT_MAX);
         if (mydata == NULL && mydata_len > 0 && CheckGap(ssn, *stream, p)) {
@@ -1049,7 +1050,12 @@ static int ReassembleUpdateAppLayer (ThreadVars *tv,
                 return 0;
 
             continue;
-        } else if (mydata == NULL || mydata_len == 0) {
+        } else if (flags & STREAM_DEPTH) {
+            // we're just called once with this flag, so make sure we pass it on
+            if (mydata == NULL && mydata_len > 0) {
+                mydata_len = 0;
+            }
+        } else if (mydata == NULL || (mydata_len == 0)) {
             /* Possibly a gap, but no new data. */
             if ((p->flags & PKT_PSEUDO_STREAM_END) == 0 || ssn->state < TCP_CLOSED)
                 SCReturnInt(0);
@@ -1057,6 +1063,8 @@ static int ReassembleUpdateAppLayer (ThreadVars *tv,
             mydata = NULL;
             mydata_len = 0;
         }
+        DEBUG_VALIDATE_BUG_ON(mydata == NULL && mydata_len > 0);
+
         SCLogDebug("%"PRIu64" got %p/%u", p->pcap_cnt, mydata, mydata_len);
         break;
     }