]> 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:40:19 +0000 (10:40 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 8 Jan 2025 16:06:13 +0000 (17:06 +0100)
for alproto_names

Ticket: 5053

src/app-layer-detect-proto.c

index 01d5536ece06f2ef56c725bc081b1676e0920d66..52e1f2922c0247412b47149543297eef1292be14 100644 (file)
@@ -158,8 +158,9 @@ typedef struct AppLayerProtoDetectCtx_ {
 
     /* Indicates the protocols that have registered themselves
      * for protocol detection.  This table is independent of the
-     * ipproto. */
-    const char *alproto_names[ALPROTO_MAX];
+     * ipproto. It should be allocated to contain ALPROTO_MAX
+     * protocols. */
+    const char **alproto_names;
 
     /* Protocol expectations, like ftp-data on tcp.
      * It should be allocated to contain ALPROTO_MAX
@@ -1724,6 +1725,10 @@ int AppLayerProtoDetectSetup(void)
         }
     }
 
+    alpd_ctx.alproto_names = SCCalloc(ALPROTO_MAX, sizeof(char *));
+    if (unlikely(alpd_ctx.alproto_names == NULL)) {
+        FatalError("Unable to alloc alproto_names.");
+    }
     // to realloc when dynamic protos are added
     alpd_ctx.expectation_proto = SCCalloc(ALPROTO_MAX, sizeof(uint8_t));
     if (unlikely(alpd_ctx.expectation_proto == NULL)) {
@@ -1760,6 +1765,8 @@ int AppLayerProtoDetectDeSetup(void)
         }
     }
 
+    SCFree(alpd_ctx.alproto_names);
+    alpd_ctx.alproto_names = NULL;
     SCFree(alpd_ctx.expectation_proto);
     alpd_ctx.expectation_proto = NULL;
 
@@ -1776,6 +1783,7 @@ void AppLayerProtoDetectRegisterProtocol(AppProto alproto, const char *alproto_n
 {
     SCEnter();
 
+    // should have just been realloced when dynamic protos is added
     if (alpd_ctx.alproto_names[alproto] == NULL)
         alpd_ctx.alproto_names[alproto] = alproto_name;