address and port: reduce memory allocs

pull/663/head
Victor Julien 13 years ago
parent 06f4fe8e0c
commit 2ce8895f0a

@ -600,27 +600,24 @@ int DetectAddressParseString(DetectAddress *dd, char *str)
char *ip2 = NULL; char *ip2 = NULL;
char *mask = NULL; char *mask = NULL;
int r = 0; int r = 0;
char ipstr[256];
while (*str != '\0' && *str == ' ') while (*str != '\0' && *str == ' ')
str++; str++;
char *ipdup = SCStrdup(str);
if (unlikely(ipdup == NULL))
return -1;
SCLogDebug("str %s", str);
/* first handle 'any' */ /* first handle 'any' */
if (strcasecmp(str, "any") == 0) { if (strcasecmp(str, "any") == 0) {
dd->flags |= ADDRESS_FLAG_ANY; dd->flags |= ADDRESS_FLAG_ANY;
SCFree(ipdup);
SCLogDebug("address is \'any\'"); SCLogDebug("address is \'any\'");
return 0; return 0;
} }
/* we dup so we can put a nul-termination in it later */ strlcpy(ipstr, str, sizeof(ipstr));
ip = ipdup; SCLogDebug("str %s", str);
/* we work with a copy so that we can put a
* nul-termination in it later */
ip = ipstr;
/* handle the negation case */ /* handle the negation case */
if (ip[0] == '!') { if (ip[0] == '!') {
@ -757,14 +754,11 @@ int DetectAddressParseString(DetectAddress *dd, char *str)
} }
SCFree(ipdup);
BUG_ON(dd->ip.family == 0); BUG_ON(dd->ip.family == 0);
return 0; return 0;
error: error:
SCFree(ipdup);
return -1; return -1;
} }

@ -1402,11 +1402,9 @@ error:
DetectPort *PortParse(char *str) { DetectPort *PortParse(char *str) {
char *port2 = NULL; char *port2 = NULL;
DetectPort *dp = NULL; DetectPort *dp = NULL;
char *portdup = SCStrdup(str);
if (unlikely(portdup == NULL)) { char portstr[16];
return NULL; strlcpy(portstr, str, sizeof(portstr));
}
dp = DetectPortInit(); dp = DetectPortInit();
if (dp == NULL) if (dp == NULL)
@ -1415,7 +1413,7 @@ DetectPort *PortParse(char *str) {
/* XXX better input validation */ /* XXX better input validation */
/* we dup so we can put a nul-termination in it later */ /* we dup so we can put a nul-termination in it later */
char *port = portdup; char *port = portstr;
/* handle the negation case */ /* handle the negation case */
if (port[0] == '!') { if (port[0] == '!') {
@ -1457,14 +1455,11 @@ DetectPort *PortParse(char *str) {
} }
} }
SCFree(portdup);
return dp; return dp;
error: error:
if (dp != NULL) if (dp != NULL)
DetectPortCleanupList(dp); DetectPortCleanupList(dp);
if (portdup) SCFree(portdup);
return NULL; return NULL;
} }

Loading…
Cancel
Save