]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Convert ParseSizeString to use pcre_copy_substring
authorVictor Julien <victor@inliniac.net>
Wed, 27 Nov 2013 20:15:48 +0000 (21:15 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 28 Nov 2013 12:48:06 +0000 (13:48 +0100)
src/util-misc.c

index 4b0847fc4537a7979c3818b883b328f1c8d72ea3..50de7158b65a728771da89e1b7fa582ed77f06d9 100644 (file)
@@ -67,8 +67,8 @@ static int ParseSizeString(const char *size, double *res)
     int r;
     int ov[MAX_SUBSTRINGS];
     int retval = 0;
-    const char *str_ptr = NULL;
-    const char *str_ptr2 = NULL;
+    char str[128];
+    char str2[128];
 
     *res = 0;
 
@@ -86,15 +86,15 @@ static int ParseSizeString(const char *size, double *res)
         goto end;
     }
 
-    r = pcre_get_substring((char *)size, ov, MAX_SUBSTRINGS, 1,
-                             &str_ptr);
+    r = pcre_copy_substring((char *)size, ov, MAX_SUBSTRINGS, 1,
+                             str, sizeof(str));
     if (r < 0) {
-        SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
+        SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring failed");
         retval = -2;
         goto end;
     }
 
-    char *endptr;
+    char *endptr, *str_ptr = str;
     errno = 0;
     *res = strtod(str_ptr, &endptr);
     if (errno == ERANGE) {
@@ -108,19 +108,19 @@ static int ParseSizeString(const char *size, double *res)
     }
 
     if (pcre_exec_ret == 3) {
-        r = pcre_get_substring((char *)size, ov, MAX_SUBSTRINGS, 2,
-                                 &str_ptr2);
+        r = pcre_copy_substring((char *)size, ov, MAX_SUBSTRINGS, 2,
+                                 str2, sizeof(str2));
         if (r < 0) {
-            SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
+            SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring failed");
             retval = -2;
             goto end;
         }
 
-        if (strcasecmp(str_ptr2, "kb") == 0) {
+        if (strcasecmp(str2, "kb") == 0) {
             *res *= 1024;
-        } else if (strcasecmp(str_ptr2, "mb") == 0) {
+        } else if (strcasecmp(str2, "mb") == 0) {
             *res *= 1024 * 1024;
-        } else if (strcasecmp(str_ptr2, "gb") == 0) {
+        } else if (strcasecmp(str2, "gb") == 0) {
             *res *= 1024 * 1024 * 1024;
         } else {
             /* not possible */
@@ -130,10 +130,6 @@ static int ParseSizeString(const char *size, double *res)
 
     retval = 0;
 end:
-    if (str_ptr != NULL)
-        pcre_free_substring(str_ptr);
-    if (str_ptr2 != NULL)
-        pcre_free_substring(str_ptr2);
     return retval;
 }