From: Philippe Antoine Date: Mon, 2 Sep 2024 08:35:11 +0000 (+0200) Subject: protodetect: use dynamic number of app-layer protos X-Git-Tag: suricata-8.0.0-beta1~610 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61657c8ec6ffb77ab602e3a4d8dc0bed3bec08cd;p=thirdparty%2Fsuricata.git protodetect: use dynamic number of app-layer protos for expectation_proto Ticket: 5053 --- diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c index dd17b560c5..01d5536ece 100644 --- a/src/app-layer-detect-proto.c +++ b/src/app-layer-detect-proto.c @@ -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();