]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: prep for dynamic smlists arrays in sigs
authorVictor Julien <victor@inliniac.net>
Mon, 23 Oct 2017 10:08:47 +0000 (12:08 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 14 Feb 2018 13:25:46 +0000 (14:25 +0100)
Initialize Signature::init_data::smlists like normal, but before use
expand them if needed.

src/detect-parse.c
src/detect.h

index c300867f31b80981296d29c85e99e22f3d3f773c..92981cd7d9a3853f191f46f2157dc156e4873506 100644 (file)
@@ -280,6 +280,25 @@ static SigTableElmt *SigTableGet(char *name)
  */
 void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
 {
+    if (list > 0 && (uint32_t)list >= s->init_data->smlists_array_size)
+    {
+        uint32_t old_size = s->init_data->smlists_array_size;
+        uint32_t new_size = (uint32_t)list + 1;
+        void *ptr = SCRealloc(s->init_data->smlists, (new_size * sizeof(SigMatch *)));
+        if (ptr == NULL)
+            abort();
+        s->init_data->smlists = ptr;
+        ptr = SCRealloc(s->init_data->smlists_tail, (new_size * sizeof(SigMatch *)));
+        if (ptr == NULL)
+            abort();
+        s->init_data->smlists_tail = ptr;
+        for (uint32_t i = old_size; i < new_size; i++) {
+            s->init_data->smlists[i] = NULL;
+            s->init_data->smlists_tail[i] = NULL;
+        }
+        s->init_data->smlists_array_size = new_size;
+    }
+
     if (s->init_data->smlists[list] == NULL) {
         s->init_data->smlists[list] = new;
         s->init_data->smlists_tail[list] = new;
@@ -1159,16 +1178,17 @@ Signature *SigAlloc (void)
         SCFree(sig);
         return NULL;
     }
-    int lists = DetectBufferTypeMaxId();
-    SCLogDebug("smlists size %d", lists);
-    sig->init_data->smlists = SCCalloc(lists, sizeof(SigMatch *));
+
+    sig->init_data->smlists_array_size = DetectBufferTypeMaxId();
+    SCLogDebug("smlists size %u", sig->init_data->smlists_array_size);
+    sig->init_data->smlists = SCCalloc(sig->init_data->smlists_array_size, sizeof(SigMatch *));
     if (sig->init_data->smlists == NULL) {
         SCFree(sig->init_data);
         SCFree(sig);
         return NULL;
     }
 
-    sig->init_data->smlists_tail = SCCalloc(lists, sizeof(SigMatch *));
+    sig->init_data->smlists_tail = SCCalloc(sig->init_data->smlists_array_size, sizeof(SigMatch *));
     if (sig->init_data->smlists_tail == NULL) {
         SCFree(sig->init_data->smlists_tail);
         SCFree(sig->init_data);
index 1c38ac493ad9e4db2a68523fdec961d2df010bda..46e4006594cf313c31915765b408fb176c99f300 100644 (file)
@@ -390,6 +390,7 @@ typedef struct SignatureInitData_ {
 
     int prefilter_list;
 
+    uint32_t smlists_array_size;
     /* holds all sm lists */
     struct SigMatch_ **smlists;
     /* holds all sm lists' tails */