]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
email/eve: use Rust function to hash buffer to hex
authorJason Ish <jason.ish@oisf.net>
Mon, 4 Jan 2021 16:48:20 +0000 (10:48 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 13 Jan 2021 08:01:05 +0000 (09:01 +0100)
Use SCMd5HashBufferToHex to hash the subject to a hex string.
Removes snprintf loop.

src/output-json-email-common.c

index 4fd79859d488c0110b67e7923a581a945308f0f0..93e54119fa83304a4bebe10b671926a72d904bbe 100644 (file)
@@ -131,15 +131,10 @@ static void EveEmailLogJSONMd5(OutputJsonEmailCtx *email_ctx, JsonBuilder *js, S
         }
         field = MimeDecFindField(entity, "subject");
         if (field != NULL) {
-            unsigned char md5[SC_MD5_LEN];
-            char smd5[256];
+            char smd5[SC_MD5_HEX_LEN + 1];
             char *value = BytesToString((uint8_t *)field->value , field->value_len);
             if (value) {
-                size_t i,x;
-                SCMd5HashBuffer((uint8_t *)value, strlen(value), md5, sizeof(md5));
-                for (i = 0, x = 0; x < sizeof(md5); x++) {
-                    i += snprintf(smd5 + i, 255 - i, "%02x", md5[x]);
-                }
+                SCMd5HashBufferToHex((uint8_t *)value, strlen(value), smd5, sizeof(smd5));
                 jb_set_string(js, "subject_md5", smd5);
                 SCFree(value);
             }