From: Victor Julien Date: Wed, 8 Apr 2015 13:34:58 +0000 (+0200) Subject: reference: use pcre_copy_substring X-Git-Tag: suricata-2.1beta4~43 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e86e1e0282e100e4f476cf46ad9fd367afeb69bf;p=thirdparty%2Fsuricata.git reference: use pcre_copy_substring --- diff --git a/src/util-reference-config.c b/src/util-reference-config.c index aea8562772..30b1a366d1 100644 --- a/src/util-reference-config.c +++ b/src/util-reference-config.c @@ -229,8 +229,8 @@ static char *SCRConfStringToLowercase(const char *str) */ static int SCRConfAddReference(char *rawstr, DetectEngineCtx *de_ctx) { - const char *system = NULL; - const char *url = NULL; + char system[64]; + char url[1024]; SCRConfReference *ref_new = NULL; SCRConfReference *ref_lookup = NULL; @@ -247,21 +247,23 @@ static int SCRConfAddReference(char *rawstr, DetectEngineCtx *de_ctx) } /* retrieve the reference system */ - ret = pcre_get_substring((char *)rawstr, ov, 30, 1, &system); + ret = pcre_copy_substring((char *)rawstr, ov, 30, 1, system, sizeof(system)); if (ret < 0) { - SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring() failed"); + SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring() failed"); goto error; } /* retrieve the reference url */ - ret = pcre_get_substring((char *)rawstr, ov, 30, 2, &url); + ret = pcre_copy_substring((char *)rawstr, ov, 30, 2, url, sizeof(url)); if (ret < 0) { - SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring() failed"); + SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring() failed"); goto error; } /* Create a new instance of the parsed Reference string */ ref_new = SCRConfAllocSCRConfReference(system, url); + if (ref_new == NULL) + goto error; /* Check if the Reference is present in the HashTable. In case it's present * ignore it, as it's a duplicate. If not present, add it to the table */ @@ -275,17 +277,9 @@ static int SCRConfAddReference(char *rawstr, DetectEngineCtx *de_ctx) SCRConfDeAllocSCRConfReference(ref_new); } - /* free the substrings */ - pcre_free_substring(system); - pcre_free_substring(url); return 0; error: - if (system) - pcre_free_substring(system); - if (url) - pcre_free_substring(url); - return -1; }