[llvm] r264237 - [libFuzzer] don't report memory leaks if we are dying due to a timeout (just use _Exit instead of exit in the timeout callback)

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 23 18:32:08 PDT 2016


Author: kcc
Date: Wed Mar 23 20:32:08 2016
New Revision: 264237

URL: http://llvm.org/viewvc/llvm-project?rev=264237&view=rev
Log:
[libFuzzer] don't report memory leaks if we are dying due to a timeout (just use _Exit instead of exit in the timeout callback)

Added:
    llvm/trunk/lib/Fuzzer/test/LeakTimeoutTest.cpp
    llvm/trunk/lib/Fuzzer/test/fuzzer-leak.test
Modified:
    llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
    llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
    llvm/trunk/lib/Fuzzer/test/fuzzer.test

Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=264237&r1=264236&r2=264237&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Wed Mar 23 20:32:08 2016
@@ -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.
   }
 }
 

Modified: llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/CMakeLists.txt?rev=264237&r1=264236&r2=264237&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/CMakeLists.txt Wed Mar 23 20:32:08 2016
@@ -22,6 +22,7 @@ set(Tests
   InitializeTest
   MemcmpTest
   LeakTest
+  LeakTimeoutTest
   NullDerefTest
   NthRunCrashTest
   RepeatedMemcmp

Added: llvm/trunk/lib/Fuzzer/test/LeakTimeoutTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/LeakTimeoutTest.cpp?rev=264237&view=auto
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/LeakTimeoutTest.cpp (added)
+++ llvm/trunk/lib/Fuzzer/test/LeakTimeoutTest.cpp Wed Mar 23 20:32:08 2016
@@ -0,0 +1,14 @@
+// Test with a leak.
+#include <cstdint>
+#include <cstddef>
+
+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;
+}
+

Added: llvm/trunk/lib/Fuzzer/test/fuzzer-leak.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/fuzzer-leak.test?rev=264237&view=auto
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/fuzzer-leak.test (added)
+++ llvm/trunk/lib/Fuzzer/test/fuzzer-leak.test Wed Mar 23 20:32:08 2016
@@ -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
+
+

Modified: llvm/trunk/lib/Fuzzer/test/fuzzer.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/fuzzer.test?rev=264237&r1=264236&r2=264237&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/fuzzer.test (original)
+++ llvm/trunk/lib/Fuzzer/test/fuzzer.test Wed Mar 23 20:32:08 2016
@@ -69,10 +69,6 @@ RUN: LLVMFuzzer-SimpleTest %t/SUB1 -runs
 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




More information about the llvm-commits mailing list