]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Use the stack for temporary memory buffers. 683/head
authorJason Ish <jason.ish@emulex.com>
Wed, 4 Dec 2013 16:01:54 +0000 (10:01 -0600)
committerJason Ish <jason.ish@emulex.com>
Wed, 4 Dec 2013 16:02:33 +0000 (10:02 -0600)
src/conf.c
src/util-error.c
src/util-error.h

index d747c0d5d22e9e2f65af38ea9fb75f38136440df..6fd6805ea8d6e9d49a833e4e6d743c4b8a954718 100644 (file)
@@ -42,6 +42,9 @@
 #include "util-debug.h"
 #include "util-path.h"
 
+/** Maximum size of a complete domain name. */
+#define NODE_NAME_MAX 1024
+
 static ConfNode *root = NULL;
 static ConfNode *root_backup = NULL;
 
@@ -63,17 +66,17 @@ ConfGetNodeOrCreate(char *name, int final)
 {
     ConfNode *parent = root;
     ConfNode *node = NULL;
-    char *tmpname;
+    char node_name[NODE_NAME_MAX];
     char *key;
     char *next;
 
-    tmpname = SCStrdup(name);
-    if (unlikely(tmpname == NULL)) {
-        SCLogWarning(SC_ERR_MEM_ALLOC,
-            "Failed to allocate memory for configuration.");
-        goto end;
+    if (strlcpy(node_name, name, sizeof(node_name)) >= sizeof(node_name)) {
+        SCLogError(SC_ERR_CONF_NAME_TOO_LONG,
+            "Configuration name too long: %s", name);
+        return NULL;
     }
-    key = tmpname;
+
+    key = node_name;
 
     do {
         if ((next = strchr(key, '.')) != NULL)
@@ -95,9 +98,6 @@ ConfGetNodeOrCreate(char *name, int final)
     } while (next != NULL);
 
 end:
-    if (tmpname != NULL)
-        SCFree(tmpname);
-
     return node;
 }
 
@@ -174,18 +174,17 @@ ConfNode *
 ConfGetNode(char *name)
 {
     ConfNode *node = root;
-    char *tmpname;
+    char node_name[NODE_NAME_MAX];
     char *key;
     char *next;
 
-    tmpname = SCStrdup(name);
-    if (unlikely(tmpname == NULL)) {
-        SCLogWarning(SC_ERR_MEM_ALLOC,
-            "Failed to allocate temp. memory while getting config node.");
+    if (strlcpy(node_name, name, sizeof(node_name)) >= sizeof(node_name)) {
+        SCLogError(SC_ERR_CONF_NAME_TOO_LONG,
+            "Configuration name too long: %s", name);
         return NULL;
     }
-    key = tmpname;
 
+    key = node_name;
     do {
         if ((next = strchr(key, '.')) != NULL)
             *next++ = '\0';
@@ -193,8 +192,6 @@ ConfGetNode(char *name)
         key = next;
     } while (next != NULL && node != NULL);
 
-    SCFree(tmpname);
-
     return node;
 }
 
index 95e9a06e3b8d3b12d279bc7227525906fd85f0fa..86575dc827fe8c0f518ce751aff0eb4f2df7ec0d 100644 (file)
@@ -281,6 +281,7 @@ const char * SCErrorToString(SCError err)
         CASE_CODE (SC_ERR_THRESHOLD_SETUP);
         CASE_CODE (SC_ERR_DNS_CONFIG);
         CASE_CODE (SC_ERR_CONF_YAML_ERROR);
+        CASE_CODE (SC_ERR_CONF_NAME_TOO_LONG);
     }
 
     return "UNKNOWN_ERROR";
index 2bb93380c74783b9ceefd970c49a0b5bdf70931f..1f5ac34fd06569b190f672117dc2e99f78a979af 100644 (file)
@@ -270,6 +270,7 @@ typedef enum {
     SC_ERR_THRESHOLD_SETUP,
     SC_ERR_DNS_CONFIG,
     SC_ERR_CONF_YAML_ERROR,
+    SC_ERR_CONF_NAME_TOO_LONG,
 } SCError;
 
 const char *SCErrorToString(SCError);