]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
conf: add value checks for datasets hash/prealloc
authorjason taylor <jtfas90@gmail.com>
Thu, 17 Oct 2019 00:26:51 +0000 (20:26 -0400)
committerVictor Julien <victor@inliniac.net>
Sun, 26 Apr 2020 08:46:09 +0000 (10:46 +0200)
Signed-off-by: jason taylor <jtfas90@gmail.com>
src/util-thash.c

index 90a4ead7944bb588f5e4b49cd934a72dff08be61..f5c9db145c00ae8cf6dadb66562c64a06f204ab3 100644 (file)
@@ -204,6 +204,17 @@ static void THashDataFree(THashTableContext *ctx, THashData *h)
 #define GET_VAR(prefix,name) \
     snprintf(varname, sizeof(varname), "%s.%s", (prefix), (name))
 
+static void THashConfigValidate(const char *confvalue, const char *varname)
+{
+    for (size_t i = 0; i < strlen(confvalue); i++) {
+        if (!isdigit(confvalue[i])) {
+            FatalError(SC_ERR_SIZE_PARSE, "Error parsing %s "
+                    "from key %s. Killing Engine",
+                    confvalue, varname);
+        }
+    }
+}
+
 /** \brief initialize the configuration
  *  \warning Not thread safe */
 static void THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
@@ -230,6 +241,9 @@ static void THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
     GET_VAR(cnf_prefix, "hash-size");
     if ((ConfGet(varname, &conf_val)) == 1)
     {
+        /* validate hash-size value is a numerical value */
+        THashConfigValidate(conf_val, varname);
+
         if (ByteExtractStringUint32(&configval, 10, strlen(conf_val),
                                     conf_val) > 0) {
             ctx->config.hash_size = configval;
@@ -239,6 +253,9 @@ static void THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
     GET_VAR(cnf_prefix, "prealloc");
     if ((ConfGet(varname, &conf_val)) == 1)
     {
+        /* validate prealloc value is a numerical value */
+        THashConfigValidate(conf_val, varname);
+
         if (ByteExtractStringUint32(&configval, 10, strlen(conf_val),
                                     conf_val) > 0) {
             ctx->config.prealloc = configval;