]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
protodetect: use dynamic number of app-layer protos
authorPhilippe Antoine <pantoine@oisf.net>
Mon, 2 Sep 2024 08:35:11 +0000 (10:35 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 8 Jan 2025 16:06:13 +0000 (17:06 +0100)
for expectation_proto

Ticket: 5053

src/app-layer-detect-proto.c

index dd17b560c5fb23df5c6a0670e9d1eec7b2eb4fc8..01d5536ece06f2ef56c725bc081b1676e0920d66 100644 (file)
@@ -161,8 +161,11 @@ typedef struct AppLayerProtoDetectCtx_ {
      * ipproto. */
     const char *alproto_names[ALPROTO_MAX];
 
-    /* Protocol expectations, like ftp-data on tcp */
-    uint8_t expectation_proto[ALPROTO_MAX];
+    /* Protocol expectations, like ftp-data on tcp.
+     * It should be allocated to contain ALPROTO_MAX
+     * app-layer protocols. For each protocol, an iptype
+     * is referenced (or 0 if there is no expectation). */
+    uint8_t *expectation_proto;
 } AppLayerProtoDetectCtx;
 
 typedef struct AppLayerProtoDetectAliases_ {
@@ -1721,6 +1724,11 @@ int AppLayerProtoDetectSetup(void)
         }
     }
 
+    // to realloc when dynamic protos are added
+    alpd_ctx.expectation_proto = SCCalloc(ALPROTO_MAX, sizeof(uint8_t));
+    if (unlikely(alpd_ctx.expectation_proto == NULL)) {
+        FatalError("Unable to alloc expectation_proto.");
+    }
     AppLayerExpectationSetup();
 
     SCReturnInt(0);
@@ -1752,6 +1760,9 @@ int AppLayerProtoDetectDeSetup(void)
         }
     }
 
+    SCFree(alpd_ctx.expectation_proto);
+    alpd_ctx.expectation_proto = NULL;
+
     SpmDestroyGlobalThreadCtx(alpd_ctx.spm_global_thread_ctx);
 
     AppLayerProtoDetectFreeAliases();