diff --git a/lib/Fuzzer/FuzzerLoop.cpp b/lib/Fuzzer/FuzzerLoop.cpp index 7f3ffd0a4fe..f09ac058a8d 100644 --- a/lib/Fuzzer/FuzzerLoop.cpp +++ b/lib/Fuzzer/FuzzerLoop.cpp @@ -164,7 +164,7 @@ void Fuzzer::AlarmCallback() { __sanitizer_print_stack_trace(); Printf("SUMMARY: libFuzzer: timeout\n"); PrintFinalStats(); - exit(Options.TimeoutExitCode); + _Exit(Options.TimeoutExitCode); // Stop right now. } } diff --git a/lib/Fuzzer/test/CMakeLists.txt b/lib/Fuzzer/test/CMakeLists.txt index 255be9c0ccd..3bda0a99baf 100644 --- a/lib/Fuzzer/test/CMakeLists.txt +++ b/lib/Fuzzer/test/CMakeLists.txt @@ -22,6 +22,7 @@ set(Tests InitializeTest MemcmpTest LeakTest + LeakTimeoutTest NullDerefTest NthRunCrashTest RepeatedMemcmp diff --git a/lib/Fuzzer/test/LeakTimeoutTest.cpp b/lib/Fuzzer/test/LeakTimeoutTest.cpp new file mode 100644 index 00000000000..3aa56c4ef65 --- /dev/null +++ b/lib/Fuzzer/test/LeakTimeoutTest.cpp @@ -0,0 +1,14 @@ +// Test with a leak. +#include +#include + +static volatile int *Sink; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + if (!Size) return 0; + Sink = new int; + Sink = new int; + while (Sink) *Sink = 0; // Infinite loop. + return 0; +} + diff --git a/lib/Fuzzer/test/fuzzer-leak.test b/lib/Fuzzer/test/fuzzer-leak.test new file mode 100644 index 00000000000..3690068371f --- /dev/null +++ b/lib/Fuzzer/test/fuzzer-leak.test @@ -0,0 +1,9 @@ +RUN: not LLVMFuzzer-LeakTest -runs=10 2>&1 | FileCheck %s --check-prefix=LEAK +LEAK: ERROR: LeakSanitizer: detected memory leaks +LEAK-NOT: DEATH: + +RUN: not LLVMFuzzer-LeakTimeoutTest -timeout=1 2>&1 | FileCheck %s --check-prefix=LEAK_TIMEOUT +LEAK_TIMEOUT: ERROR: libFuzzer: timeout after +LEAK_TIMEOUT-NOT: LeakSanitizer + + diff --git a/lib/Fuzzer/test/fuzzer.test b/lib/Fuzzer/test/fuzzer.test index 240209d1c02..9aca950ec45 100644 --- a/lib/Fuzzer/test/fuzzer.test +++ b/lib/Fuzzer/test/fuzzer.test @@ -69,10 +69,6 @@ RUN: LLVMFuzzer-SimpleTest %t/SUB1 -runs=0 2>&1 | FileCheck %s --check-prefix=SU SUBDIRS: READ units: 3 RUN: rm -rf %t/SUB1 -RUN: not LLVMFuzzer-LeakTest -runs=10 2>&1 | FileCheck %s --check-prefix=LEAK -LEAK: ERROR: LeakSanitizer: detected memory leaks -LEAK-NOT: DEATH: - RUN: mkdir -p %t RUN: echo abcd > %t/NthRunCrashTest.in RUN: LLVMFuzzer-NthRunCrashTest %t/NthRunCrashTest.in