Add support for standalone leak-sanitizer, introducting the environment

variable AFL_USE_LSAN.

AFL_USE_LSAN introduces the macro __AFL_CHECK_LEAK() which will check
for a memory leak when the macro is run. This is especially helpful
when using __AFL_LOOP().

If __AFL_LEAK_CHECK() is not used when AFL_USE_LSAN=1 is set,
the leak checker will run when the program exits.
This commit is contained in:
Joshua Rogers
2021-04-02 22:23:11 +00:00
parent e98cd00822
commit 920e9402a4
14 changed files with 120 additions and 17 deletions

View File

@ -781,6 +781,19 @@ static void set_up_environment(void) {
}
x = get_afl_env("LSAN_OPTIONS");
if (x) {
if (!strstr(x, "exit_code=" STRINGIFY(LSAN_ERROR))) {
FATAL("Custom LSAN_OPTIONS set without exit_code=" STRINGIFY(
LSAN_ERROR) " - please fix!");
}
}
setenv("ASAN_OPTIONS",
"abort_on_error=1:"
"detect_leaks=0:"
@ -818,6 +831,12 @@ static void set_up_environment(void) {
"handle_sigfpe=0:"
"handle_sigill=0", 0);
setenv("LSAN_OPTIONS",
"exitcode=" STRINGIFY(MSAN_ERROR) ":"
"fast_unwind_on_malloc=0",
0);
if (get_afl_env("AFL_PRELOAD")) {
if (qemu_mode) {