]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mime: compute full body md5 9120/head
authorPhilippe Antoine <pantoine@oisf.net>
Fri, 16 Jun 2023 13:28:38 +0000 (15:28 +0200)
committerVictor Julien <vjulien@oisf.net>
Fri, 30 Jun 2023 18:49:14 +0000 (20:49 +0200)
Previously, the problem was that nested headers/boundaries were not
used to compute the hash

Solution is to move up the call to the hash computation from
ProcessMimeBody to its caller ProcessMimeEntity, and add a set of
conditions to ensure that we are not in the principal headers.

Ticket: #6185
(cherry picked from commit a3168fda787d4f4eee45f5c84bcc1709f207ae0a)

src/util-decode-mime.c

index 6d2ef01f9a434949b9a5413586a28f17624d7060..d5e2f1c2e5a916d446d5938d99863d5b48cab682 100644 (file)
@@ -2244,18 +2244,6 @@ static int ProcessMimeBody(const uint8_t *buf, uint32_t len,
     int body_found = 0;
     uint32_t tlen;
 
-#ifdef HAVE_NSS
-    if (MimeDecGetConfig()->body_md5) {
-        if (state->body_begin == 1) {
-            if (state->md5_ctx == NULL) {
-                state->md5_ctx = HASH_Create(HASH_AlgMD5);
-                HASH_Begin(state->md5_ctx);
-            }
-        }
-        HASH_Update(state->md5_ctx, buf, len + state->current_line_delimiter_len);
-    }
-#endif
-
     /* pass empty lines on if we're parsing the body, otherwise we have no use
      * for them, and in fact they would disrupt the state tracking */
     if (len == 0) {
@@ -2385,6 +2373,21 @@ static int ProcessMimeEntity(const uint8_t *buf, uint32_t len,
                 MAX_LINE_LEN);
     }
 
+    if ((state->state_flag != HEADER_READY && state->state_flag != HEADER_STARTED) ||
+            (state->stack->top->data->ctnt_flags & CTNT_IS_BODYPART)) {
+#ifdef HAVE_NSS
+        if (MimeDecGetConfig()->body_md5) {
+            if (state->body_begin == 1) {
+                if (state->md5_ctx == NULL) {
+                    state->md5_ctx = HASH_Create(HASH_AlgMD5);
+                    HASH_Begin(state->md5_ctx);
+                }
+            }
+            HASH_Update(state->md5_ctx, buf, len + state->current_line_delimiter_len);
+        }
+#endif
+    }
+
     /* Looking for headers */
     if (state->state_flag == HEADER_READY ||
             state->state_flag == HEADER_STARTED) {