]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util-decode-mime: fix some unittests
authorEric Leblond <eric@regit.org>
Wed, 23 Sep 2015 12:49:03 +0000 (14:49 +0200)
committerEric Leblond <eric@regit.org>
Tue, 6 Oct 2015 21:30:46 +0000 (23:30 +0200)
Unittests were failling when ASAN is activated because it was
finding some read outside of bounds. This patch fixes the different
reported issues.

src/util-decode-mime.c

index 38850c78af1e2d48f8d4a0680639cfa9e9b963c6..6eee1a6a09b38402532df2463d73763fb4296bd4 100644 (file)
@@ -2852,7 +2852,12 @@ static int MimeDecParseFullMsgTest02(void)
         return -1;
     }
 
-    if (memcmp(field->value, "subject2", sizeof("subject2")) != 0) {
+    if (field->value_len != sizeof("subject2") - 1) {
+        SCLogInfo("Warning: failed to get subject");
+        return -1;
+    }
+
+    if (memcmp(field->value, "subject2", field->value_len) != 0) {
         SCLogInfo("Warning: failed to get subject");
         return -1;
     }
@@ -2878,7 +2883,7 @@ static int MimeBase64DecodeTest01(void)
     char *base64msg = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QU"
             "VJTVFVWV1hZWjEyMzQ1Njc4OTBAIyQlXiYqKCktPV8rLC4vOydbXTw+Pzo=";
 
-    uint8_t *dst = SCMalloc(strlen(msg)-1);
+    uint8_t *dst = SCMalloc(strlen(msg) + 1);
     if (dst == NULL)
         return 0;
 
@@ -2888,6 +2893,8 @@ static int MimeBase64DecodeTest01(void)
         ret = 0;
     }
 
+    SCFree(dst);
+
     return ret;
 }