]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
json-email: fix coverity alert
authorEric Leblond <eric@regit.org>
Wed, 21 Oct 2015 12:50:25 +0000 (14:50 +0200)
committerEric Leblond <eric@regit.org>
Wed, 21 Oct 2015 12:50:25 +0000 (14:50 +0200)
The code was not correct and coverity did detect a potential
overflow problem that should not happen because of the structure
of md5 string and of format.

src/output-json-email-common.c

index 33264d471d610240ef4589af4f5ac4be57430c02..88cd3acf4b2c37439447f88d8f093acb770426df 100644 (file)
@@ -140,13 +140,13 @@ static void JsonEmailLogJSONMd5(OutputJsonEmailCtx *email_ctx, json_t *js, SMTPT
         field = MimeDecFindField(entity, "subject");
         if (field != NULL) {
             unsigned char md5[MD5_LENGTH];
-            char smd5[2 * MD5_LENGTH + 1];
+            char smd5[256];
             char *value = BytesToString((uint8_t *)field->value , field->value_len);
             if (value) {
                 size_t i,x;
                 HASH_HashBuf(HASH_AlgMD5, md5, (unsigned char *)value, strlen(value));
                 for (i = 0, x = 0; x < sizeof(md5); x++) {
-                    i += snprintf(smd5 + i, 255-i, "%02x", md5[x]);
+                    i += snprintf(smd5 + i, 255 - i, "%02x", md5[x]);
                 }
                 json_object_set_new(js, "subject_md5", json_string(smd5));
                 SCFree(value);