From: Eric Leblond Date: Wed, 23 Sep 2015 12:49:03 +0000 (+0200) Subject: util-decode-mime: fix some unittests X-Git-Tag: suricata-3.0RC1~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53419b93c861b948890bb2ac12e13982e72ae726;p=thirdparty%2Fsuricata.git util-decode-mime: fix some unittests Unittests were failling when ASAN is activated because it was finding some read outside of bounds. This patch fixes the different reported issues. --- diff --git a/src/util-decode-mime.c b/src/util-decode-mime.c index 38850c78af..6eee1a6a09 100644 --- a/src/util-decode-mime.c +++ b/src/util-decode-mime.c @@ -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; }