]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
email/md5: optimize md5 handling 5722/head
authorVictor Julien <victor@inliniac.net>
Tue, 12 Jan 2021 21:22:27 +0000 (22:22 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 13 Jan 2021 08:01:14 +0000 (09:01 +0100)
src/output-json-email-common.c

index 93e54119fa83304a4bebe10b671926a72d904bbe..250d7d17d743fb5d1fa92453dded3a9c16409afe 100644 (file)
@@ -124,20 +124,15 @@ static bool EveEmailJsonArrayFromCommaList(JsonBuilder *js, const uint8_t *val,
 static void EveEmailLogJSONMd5(OutputJsonEmailCtx *email_ctx, JsonBuilder *js, SMTPTransaction *tx)
 {
     if (email_ctx->flags & LOG_EMAIL_SUBJECT_MD5) {
-        MimeDecField *field;
         MimeDecEntity *entity = tx->msg_tail;
         if (entity == NULL) {
             return;
         }
-        field = MimeDecFindField(entity, "subject");
+        MimeDecField *field = MimeDecFindField(entity, "subject");
         if (field != NULL) {
             char smd5[SC_MD5_HEX_LEN + 1];
-            char *value = BytesToString((uint8_t *)field->value , field->value_len);
-            if (value) {
-                SCMd5HashBufferToHex((uint8_t *)value, strlen(value), smd5, sizeof(smd5));
-                jb_set_string(js, "subject_md5", smd5);
-                SCFree(value);
-            }
+            SCMd5HashBufferToHex((uint8_t *)field->value, field->value_len, smd5, sizeof(smd5));
+            jb_set_string(js, "subject_md5", smd5);
         }
     }
 
@@ -147,12 +142,10 @@ static void EveEmailLogJSONMd5(OutputJsonEmailCtx *email_ctx, JsonBuilder *js, S
             size_t x;
             int i;
             char s[256];
-            if (likely(s != NULL)) {
-                for (i = 0, x = 0; x < sizeof(mime_state->md5); x++) {
-                    i += snprintf(s + i, 255-i, "%02x", mime_state->md5[x]);
-                }
-                jb_set_string(js, "body_md5", s);
+            for (i = 0, x = 0; x < sizeof(mime_state->md5); x++) {
+                i += snprintf(s + i, 255 - i, "%02x", mime_state->md5[x]);
             }
+            jb_set_string(js, "body_md5", s);
         }
     }
 }