]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Fix detect tag error handling.
authorVictor Julien <victor@inliniac.net>
Tue, 3 Jul 2012 12:09:17 +0000 (14:09 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 3 Jul 2012 12:09:17 +0000 (14:09 +0200)
src/detect-tag.c

index 286835dafbde609fe60573843eafba18b3ff3cb4..1715eafef85e252bd02bcb73eadef8aecfbdf237 100644 (file)
@@ -180,7 +180,7 @@ DetectTagData *DetectTagParse (char *tagstr)
     }
 
     res = pcre_get_substring((char *)tagstr, ov, MAX_SUBSTRINGS, 1, &str_ptr);
-    if (res < 0) {
+    if (res < 0 || str_ptr == NULL) {
         SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
         goto error;
     }
@@ -194,10 +194,8 @@ DetectTagData *DetectTagParse (char *tagstr)
         SCLogError(SC_ERR_INVALID_VALUE, "Invalid argument type. Must be session or host (%s)", tagstr);
         goto error;
     }
-    if (str_ptr != NULL) {
-        pcre_free_substring(str_ptr);
-        str_ptr = NULL;
-    }
+    pcre_free_substring(str_ptr);
+    str_ptr = NULL;
 
     /* default tag is 256 packets from session or dst host */
     td.count = DETECT_TAG_MAX_PKTS;
@@ -206,7 +204,7 @@ DetectTagData *DetectTagParse (char *tagstr)
 
     if (ret > 4) {
         res = pcre_get_substring((char *)tagstr, ov, MAX_SUBSTRINGS, 3, &str_ptr);
-        if (res < 0) {
+        if (res < 0 || str_ptr == NULL) {
             SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
             goto error;
         }
@@ -218,13 +216,11 @@ DetectTagData *DetectTagParse (char *tagstr)
             goto error;
         }
 
-        if (str_ptr != NULL) {
-            pcre_free_substring(str_ptr);
-            str_ptr = NULL;
-        }
+        pcre_free_substring(str_ptr);
+        str_ptr = NULL;
 
         res = pcre_get_substring((char *)tagstr, ov, MAX_SUBSTRINGS, 4, &str_ptr);
-        if (res < 0) {
+        if (res < 0 || str_ptr == NULL) {
             SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
             goto error;
         }
@@ -244,15 +240,13 @@ DetectTagData *DetectTagParse (char *tagstr)
             goto error;
         }
 
-        if (str_ptr != NULL) {
-            pcre_free_substring(str_ptr);
-            str_ptr = NULL;
-        }
+        pcre_free_substring(str_ptr);
+        str_ptr = NULL;
 
         /* if specified, overwrite it */
         if (ret == 7) {
             res = pcre_get_substring((char *)tagstr, ov, MAX_SUBSTRINGS, 6, &str_ptr);
-            if (res < 0) {
+            if (res < 0 || str_ptr == NULL) {
                 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
                 goto error;
             }
@@ -271,10 +265,8 @@ DetectTagData *DetectTagParse (char *tagstr)
                 SCLogWarning(SC_ERR_INVALID_VALUE, "Argument direction doesn't make sense for type \"session\" (%s [%"PRIu8"])", tagstr, td.type);
             }
 
-            if (str_ptr != NULL) {
-                pcre_free_substring(str_ptr);
-                str_ptr = NULL;
-            }
+            pcre_free_substring(str_ptr);
+            str_ptr = NULL;
         }
     }
 
@@ -285,9 +277,6 @@ DetectTagData *DetectTagParse (char *tagstr)
     }
 
     memcpy(real_td, &td, sizeof(DetectTagData));
-
-    if (str_ptr != NULL)
-        pcre_free_substring(str_ptr);
     return real_td;
 
 error: