]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect-email.c: don't return NULL for empty buffer
authorAlice Akaki <akakialice@gmail.com>
Mon, 24 Mar 2025 21:08:31 +0000 (17:08 -0400)
committerVictor Julien <victor@inliniac.net>
Thu, 27 Mar 2025 05:52:30 +0000 (06:52 +0100)
Just return NULL if tx->mime_state is NULL or if SCDetectMimeEmailGetData return 0

Fixes:
09db7c7 ("detect: add mime email.subject keyword")
90aab0d ("detect: add email.from")

src/detect-email.c

index 74b151142c3597ade2c04e069404a6314eed79eb..a88122e92ddd0ea3e55f4ec7472e679be262586f 100644 (file)
@@ -48,13 +48,10 @@ static InspectionBuffer *GetMimeEmailFromData(DetectEngineThreadCtx *det_ctx,
         const uint8_t *b_email_from = NULL;
         uint32_t b_email_from_len = 0;
 
-        if ((tx->mime_state != NULL)) {
-            if (SCDetectMimeEmailGetData(
-                        tx->mime_state, &b_email_from, &b_email_from_len, "from") != 1)
-                return NULL;
-        }
+        if (tx->mime_state == NULL)
+            return NULL;
 
-        if (b_email_from == NULL || b_email_from_len == 0)
+        if (SCDetectMimeEmailGetData(tx->mime_state, &b_email_from, &b_email_from_len, "from") != 1)
             return NULL;
 
         InspectionBufferSetup(det_ctx, list_id, buffer, b_email_from, b_email_from_len);
@@ -85,13 +82,11 @@ static InspectionBuffer *GetMimeEmailSubjectData(DetectEngineThreadCtx *det_ctx,
         const uint8_t *b_email_sub = NULL;
         uint32_t b_email_sub_len = 0;
 
-        if ((tx->mime_state != NULL)) {
-            if (SCDetectMimeEmailGetData(
-                        tx->mime_state, &b_email_sub, &b_email_sub_len, "subject") != 1)
-                return NULL;
-        }
+        if (tx->mime_state == NULL)
+            return NULL;
 
-        if (b_email_sub == NULL || b_email_sub_len == 0)
+        if (SCDetectMimeEmailGetData(tx->mime_state, &b_email_sub, &b_email_sub_len, "subject") !=
+                1)
             return NULL;
 
         InspectionBufferSetup(det_ctx, list_id, buffer, b_email_sub, b_email_sub_len);