From: Victor Julien Date: Mon, 7 Sep 2020 09:38:11 +0000 (+0200) Subject: detect/dataset: error if set couldn't be fully loaded X-Git-Tag: suricata-6.0.0-rc1~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6cf4b33353131f2705f3e0e3cb4091bf4613a31;p=thirdparty%2Fsuricata.git detect/dataset: error if set couldn't be fully loaded --- diff --git a/src/detect-dataset.c b/src/detect-dataset.c index ea0a1b0d19..b098c428a6 100644 --- a/src/detect-dataset.c +++ b/src/detect-dataset.c @@ -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)) diff --git a/src/util-thash.c b/src/util-thash.c index 717605d80e..876a9cac67 100644 --- a/src/util-thash.c +++ b/src/util-thash.c @@ -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 */ diff --git a/src/util-thash.h b/src/util-thash.h index 692a6ee683..96ee8e0579 100644 --- a/src/util-thash.h +++ b/src/util-thash.h @@ -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