Use the stack for temporary memory buffers.

pull/683/head
Jason Ish 12 years ago
parent ab7091927e
commit eaff01a57f

@ -42,6 +42,9 @@
#include "util-debug.h" #include "util-debug.h"
#include "util-path.h" #include "util-path.h"
/** Maximum size of a complete domain name. */
#define NODE_NAME_MAX 1024
static ConfNode *root = NULL; static ConfNode *root = NULL;
static ConfNode *root_backup = NULL; static ConfNode *root_backup = NULL;
@ -63,17 +66,17 @@ ConfGetNodeOrCreate(char *name, int final)
{ {
ConfNode *parent = root; ConfNode *parent = root;
ConfNode *node = NULL; ConfNode *node = NULL;
char *tmpname; char node_name[NODE_NAME_MAX];
char *key; char *key;
char *next; char *next;
tmpname = SCStrdup(name); if (strlcpy(node_name, name, sizeof(node_name)) >= sizeof(node_name)) {
if (unlikely(tmpname == NULL)) { SCLogError(SC_ERR_CONF_NAME_TOO_LONG,
SCLogWarning(SC_ERR_MEM_ALLOC, "Configuration name too long: %s", name);
"Failed to allocate memory for configuration."); return NULL;
goto end;
} }
key = tmpname;
key = node_name;
do { do {
if ((next = strchr(key, '.')) != NULL) if ((next = strchr(key, '.')) != NULL)
@ -95,9 +98,6 @@ ConfGetNodeOrCreate(char *name, int final)
} while (next != NULL); } while (next != NULL);
end: end:
if (tmpname != NULL)
SCFree(tmpname);
return node; return node;
} }
@ -174,18 +174,17 @@ ConfNode *
ConfGetNode(char *name) ConfGetNode(char *name)
{ {
ConfNode *node = root; ConfNode *node = root;
char *tmpname; char node_name[NODE_NAME_MAX];
char *key; char *key;
char *next; char *next;
tmpname = SCStrdup(name); if (strlcpy(node_name, name, sizeof(node_name)) >= sizeof(node_name)) {
if (unlikely(tmpname == NULL)) { SCLogError(SC_ERR_CONF_NAME_TOO_LONG,
SCLogWarning(SC_ERR_MEM_ALLOC, "Configuration name too long: %s", name);
"Failed to allocate temp. memory while getting config node.");
return NULL; return NULL;
} }
key = tmpname;
key = node_name;
do { do {
if ((next = strchr(key, '.')) != NULL) if ((next = strchr(key, '.')) != NULL)
*next++ = '\0'; *next++ = '\0';
@ -193,8 +192,6 @@ ConfGetNode(char *name)
key = next; key = next;
} while (next != NULL && node != NULL); } while (next != NULL && node != NULL);
SCFree(tmpname);
return node; return node;
} }

@ -281,6 +281,7 @@ const char * SCErrorToString(SCError err)
CASE_CODE (SC_ERR_THRESHOLD_SETUP); CASE_CODE (SC_ERR_THRESHOLD_SETUP);
CASE_CODE (SC_ERR_DNS_CONFIG); CASE_CODE (SC_ERR_DNS_CONFIG);
CASE_CODE (SC_ERR_CONF_YAML_ERROR); CASE_CODE (SC_ERR_CONF_YAML_ERROR);
CASE_CODE (SC_ERR_CONF_NAME_TOO_LONG);
} }
return "UNKNOWN_ERROR"; return "UNKNOWN_ERROR";

@ -270,6 +270,7 @@ typedef enum {
SC_ERR_THRESHOLD_SETUP, SC_ERR_THRESHOLD_SETUP,
SC_ERR_DNS_CONFIG, SC_ERR_DNS_CONFIG,
SC_ERR_CONF_YAML_ERROR, SC_ERR_CONF_YAML_ERROR,
SC_ERR_CONF_NAME_TOO_LONG,
} SCError; } SCError;
const char *SCErrorToString(SCError); const char *SCErrorToString(SCError);

Loading…
Cancel
Save