]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
reference: use pcre_copy_substring
authorVictor Julien <victor@inliniac.net>
Wed, 8 Apr 2015 13:34:58 +0000 (15:34 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 24 Apr 2015 10:37:48 +0000 (12:37 +0200)
src/util-reference-config.c

index aea8562772c659242a0fe83f99a053e51c234638..30b1a366d1df21218e22a38991c20d4cc3d363c2 100644 (file)
@@ -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;
 }