reference: use pcre_copy_substring

pull/1416/merge
Victor Julien 11 years ago
parent cc38df8074
commit e86e1e0282

@ -229,8 +229,8 @@ static char *SCRConfStringToLowercase(const char *str)
*/ */
static int SCRConfAddReference(char *rawstr, DetectEngineCtx *de_ctx) static int SCRConfAddReference(char *rawstr, DetectEngineCtx *de_ctx)
{ {
const char *system = NULL; char system[64];
const char *url = NULL; char url[1024];
SCRConfReference *ref_new = NULL; SCRConfReference *ref_new = NULL;
SCRConfReference *ref_lookup = NULL; SCRConfReference *ref_lookup = NULL;
@ -247,21 +247,23 @@ static int SCRConfAddReference(char *rawstr, DetectEngineCtx *de_ctx)
} }
/* retrieve the reference system */ /* 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) { 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; goto error;
} }
/* retrieve the reference url */ /* 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) { 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; goto error;
} }
/* Create a new instance of the parsed Reference string */ /* Create a new instance of the parsed Reference string */
ref_new = SCRConfAllocSCRConfReference(system, url); 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 /* 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 */ * 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); SCRConfDeAllocSCRConfReference(ref_new);
} }
/* free the substrings */
pcre_free_substring(system);
pcre_free_substring(url);
return 0; return 0;
error: error:
if (system)
pcre_free_substring(system);
if (url)
pcre_free_substring(url);
return -1; return -1;
} }

Loading…
Cancel
Save