Hi,
I'm trying to track down some strange behavior I get when using
afl-clang-fast with memory sanitizer.
I'm not sure how widely this is used and if it's considered supported,
but something weird is going on here.
Take this example code (let's name it test.c):
#include <stdio.h>
#include <string.h>
int main()
{
char text[100];
sprintf(text, "hello");
printf("%lu\n", strlen(text));
}
This code should be completely valid and not access any uninitialized
memory. A char array with 100 bytes is initialized on the stack,
sprintf fills that with the 0-terminated string "hello" and strlen is
called on that string.
If I do
AFL_USE_MSAN=1 afl-clang-fast test.c
./a.out
I get an error from msan:
Uninitialized bytes in __interceptor_strlen at offset 0 inside [0x7ffc50164110, 6)
==6454==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x4972c0 in main /tmp/test.c:7:2
#1 0x7f690d9b878f in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.23-r2/work/glibc-2.23/csu/../csu/libc-start.c:289
#2 0x419868 in _start (/tmp/a.out+0x419868)
SUMMARY: MemorySanitizer: use-of-uninitialized-value /tmp/test.c:7:2 in main
Exiting
However if I do the same with plain clang + msan, it works fine:
clang -fsanitize=memory test.c
./a.out
This seems to depend on a number of conditions to show the error. If I
comment out the #include lines (which gives some warnings), the error
will disappear. Also just trying to print the "text" variable (and not
calling strlen on it) doesn't give an error.
Has anyone any ideas what's wrong here and if this is a bug in
afl-clang-fast or in msan (or if I'm missing something here)?
--
Hanno Böck
https://hboeck.de/
mail/jabber:
ha...@hboeck.de
GPG: BBB51E42