]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/dataset: error if set couldn't be fully loaded
authorVictor Julien <victor@inliniac.net>
Mon, 7 Sep 2020 09:38:11 +0000 (11:38 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 7 Sep 2020 12:24:26 +0000 (14:24 +0200)
src/detect-dataset.c
src/util-thash.c
src/util-thash.h

index ea0a1b0d19a910d4c40583dca4c5b890f6c42b8c..b098c428a615dbdf77a03d8109b8c233590b8ae0 100644 (file)
@@ -377,6 +377,10 @@ int DetectDatasetSetup (DetectEngineCtx *de_ctx, Signature *s, const char *rawst
                 "failed to set up dataset '%s'.", name);
         return -1;
     }
+    if (set->hash && SC_ATOMIC_GET(set->hash->memcap_reached)) {
+        SCLogError(SC_ERR_THASH_INIT, "dataset too large for set memcap");
+        return -1;
+    }
 
     cd = SCCalloc(1, sizeof(DetectDatasetData));
     if (unlikely(cd == NULL))
index 717605d80e7656e285388377e2f86ce8309ebd0c..876a9cac67fcc26bfde7e98a13587ebcfae24d78 100644 (file)
@@ -473,6 +473,10 @@ static THashData *THashDataGetNew(THashTableContext *ctx, void *data)
                 return NULL;
             }
 
+            if (!SC_ATOMIC_GET(ctx->memcap_reached)) {
+                SC_ATOMIC_SET(ctx->memcap_reached, true);
+            }
+
             /* freed data, but it's unlocked */
         } else {
             /* now see if we can alloc a new data */
index 692a6ee683e62ce9aa2ef73e5b21def068ec027d..96ee8e05790e5380da1bacbc6ff644e6d36eb487 100644 (file)
@@ -152,6 +152,8 @@ typedef struct THashTableContext_ {
 
     THashConfig config;
 
+    /* flag set if memcap was reached at least once. */
+    SC_ATOMIC_DECLARE(bool, memcap_reached);
 } THashTableContext;
 
 /** \brief check if a memory alloc would fit in the memcap