]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: properly size det_ctx::non_mpm_id_array
authorVictor Julien <victor@inliniac.net>
Sat, 17 Jan 2015 10:54:38 +0000 (11:54 +0100)
committerVictor Julien <victor@inliniac.net>
Sat, 17 Jan 2015 12:36:46 +0000 (13:36 +0100)
Track which sgh has the higest non-mpm sig count and use that value
to size the det_ctx::non_mpm_id_array array.

src/detect-engine-siggroup.c
src/detect-engine.c
src/detect.h

index 08c298159c0a93cbdbe91560331dd12ddc877aef..a7ecbafd9abdaa828d602bcce3711e99d92087bb 100644 (file)
@@ -1689,7 +1689,9 @@ void SigGroupHeadSetFilestoreCount(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
     return;
 }
 
-/* build an array of rule id's for sigs with no mpm */
+/** \brief build an array of rule id's for sigs with no mpm
+ *  Also updated de_ctx::non_mpm_store_cnt_max to track the highest cnt
+ */
 int SigGroupHeadBuildNonMpmArray(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
 {
     Signature *s = NULL;
@@ -1738,6 +1740,11 @@ int SigGroupHeadBuildNonMpmArray(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
             sgh->non_mpm_store_cnt++;
         }
     }
+
+    /* track highest cnt for any sgh in our de_ctx */
+    if (sgh->non_mpm_store_cnt > de_ctx->non_mpm_store_cnt_max)
+        de_ctx->non_mpm_store_cnt_max = sgh->non_mpm_store_cnt;
+
     return 0;
 }
 
index 211d330f56ed6e7ab4fceb48a63edb1098a00190..cf43590fc48b115b3bb75b91d8df24f9c591b3d2 100644 (file)
@@ -1290,8 +1290,12 @@ static TmEcode ThreadCtxDoInit (DetectEngineCtx *de_ctx, DetectEngineThreadCtx *
         PmqSetup(&det_ctx->smsg_pmq[i], de_ctx->max_fp_id);
     }
 
-    det_ctx->non_mpm_id_array =  SCCalloc(32000, sizeof(SigIntId)); // TODO proper size or dynamicly grow
-    BUG_ON(det_ctx->non_mpm_id_array == NULL);
+    /* sized to the max of our sgh settings. A max setting of 0 implies that all
+     * sgh's have: sgh->non_mpm_store_cnt == 0 */
+    if (de_ctx->non_mpm_store_cnt_max > 0) {
+        det_ctx->non_mpm_id_array =  SCCalloc(de_ctx->non_mpm_store_cnt_max, sizeof(SigIntId));
+        BUG_ON(det_ctx->non_mpm_id_array == NULL);
+    }
 
     /* IP-ONLY */
     DetectEngineIPOnlyThreadInit(de_ctx,&det_ctx->io_ctx);
index 5ff05bf954793c522aab48704f0fd0bd871967d5..4a7ce480fc3b531a24aef1530e7322d3c8800c0b 100644 (file)
@@ -587,6 +587,10 @@ typedef struct DetectEngineCtx_ {
 
     uint32_t signum;
 
+    /** Maximum value of all our sgh's non_mpm_store_cnt setting,
+     *  used to alloc det_ctx::non_mpm_id_array */
+    uint32_t non_mpm_store_cnt_max;
+
     /* used by the signature ordering module */
     struct SCSigOrderFunc_ *sc_sig_order_funcs;
 
@@ -977,8 +981,8 @@ typedef struct SigGroupHead_ {
     SignatureMask *mask_array;
 #endif
 
-    SignatureNonMpmStore *non_mpm_store_array;
-    uint32_t non_mpm_store_cnt; // size is cnt * sizeof(SignatureNonMpmStore)
+    SignatureNonMpmStore *non_mpm_store_array; // size is non_mpm_store_cnt * sizeof(SignatureNonMpmStore)
+    uint32_t non_mpm_store_cnt;
 
     /* pattern matcher instances */
     MpmCtx *mpm_proto_other_ctx;