[compiler-rt] r312993 - [libfuzzer] Compare TotalNumberOfRuns with MaxNumberOfRuns when testing a memory leak.

Max Moroz via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 11 19:01:55 PDT 2017


Author: dor1s
Date: Mon Sep 11 19:01:54 2017
New Revision: 312993

URL: http://llvm.org/viewvc/llvm-project?rev=312993&view=rev
Log:
[libfuzzer] Compare TotalNumberOfRuns with MaxNumberOfRuns when testing a memory leak.

Summary:
Fuzzer::TryDetectingAMemoryLeak may call ExecuteCallback which would
increment TotalNumberOfRuns, but it doesn't respect Options.MaxNumberOfRuns
value specified by a user.

Context: https://github.com/google/oss-fuzz/issues/822#issuecomment-328153970

Reviewers: kcc

Reviewed By: kcc

Differential Revision: https://reviews.llvm.org/D37632

Added:
    compiler-rt/trunk/test/fuzzer/max-number-of-runs.test
Modified:
    compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp?rev=312993&r1=312992&r2=312993&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp Mon Sep 11 19:01:54 2017
@@ -525,6 +525,8 @@ void Fuzzer::TryDetectingAMemoryLeak(con
                                      bool DuringInitialCorpusExecution) {
   if (!HasMoreMallocsThanFrees) return;  // mallocs==frees, a leak is unlikely.
   if (!Options.DetectLeaks) return;
+  if (!DuringInitialCorpusExecution &&
+      TotalNumberOfRuns >= Options.MaxNumberOfRuns) return;
   if (!&(EF->__lsan_enable) || !&(EF->__lsan_disable) ||
       !(EF->__lsan_do_recoverable_leak_check))
     return;  // No lsan.

Added: compiler-rt/trunk/test/fuzzer/max-number-of-runs.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/max-number-of-runs.test?rev=312993&view=auto
==============================================================================
--- compiler-rt/trunk/test/fuzzer/max-number-of-runs.test (added)
+++ compiler-rt/trunk/test/fuzzer/max-number-of-runs.test Mon Sep 11 19:01:54 2017
@@ -0,0 +1,10 @@
+RUN: %cpp_compiler %S/AccumulateAllocationsTest.cpp -o %t-AccumulateAllocationsTest
+
+RUN: %t-AccumulateAllocationsTest -seed=1 -runs=2 2>&1 | FileCheck %s --check-prefix=CHECK1
+CHECK1: Done 2 runs
+
+RUN: %t-AccumulateAllocationsTest -seed=1 -runs=3 2>&1 | FileCheck %s --check-prefix=CHECK2
+CHECK2: Done 3 runs
+
+RUN: %t-AccumulateAllocationsTest -seed=1 -runs=4 2>&1 | FileCheck %s --check-prefix=CHECK3
+CHECK3: Done 4 runs




More information about the llvm-commits mailing list