[compiler-rt] r320643 - [libFuzzer] Add dummy call of LLVMFuzzerTestOneInput to afl_driver.

Matt Morehouse via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 14:02:44 PST 2017


Author: morehouse
Date: Wed Dec 13 14:02:44 2017
New Revision: 320643

URL: http://llvm.org/viewvc/llvm-project?rev=320643&view=rev
Log:
[libFuzzer] Add dummy call of LLVMFuzzerTestOneInput to afl_driver.

Summary:
Add dummy call of LLVMFuzzerTestOneInput to afl_driver before it starts
executing on actual inputs. Do this so that first time initialization
performed by LLVMFuzzerTestOneInput is not considered code covered by
a particular input.

Patch By: metzman

Reviewers: kcc, morehouse

Reviewed By: kcc

Subscribers: llvm-commits, Sanitizers

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

Modified:
    compiler-rt/trunk/lib/fuzzer/afl/afl_driver.cpp

Modified: compiler-rt/trunk/lib/fuzzer/afl/afl_driver.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/afl/afl_driver.cpp?rev=320643&r1=320642&r2=320643&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/afl/afl_driver.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/afl/afl_driver.cpp Wed Dec 13 14:02:44 2017
@@ -88,7 +88,7 @@ statistics from the file. If that fails
 // to the file as well, if the error occurs after the duplication is performed.
 #define CHECK_ERROR(cond, error_message)                                       \
   if (!(cond)) {                                                               \
-    fprintf(stderr, (error_message));                                          \
+    fprintf(stderr, "%s\n", (error_message));                                  \
     abort();                                                                   \
   }
 
@@ -308,6 +308,12 @@ int main(int argc, char **argv) {
     return ExecuteFilesOnyByOne(argc, argv);
 
   assert(N > 0);
+
+  // Call LLVMFuzzerTestOneInput here so that coverage caused by initialization
+  // on the first execution of LLVMFuzzerTestOneInput is ignored.
+  uint8_t dummy_input[1] = {0};
+  LLVMFuzzerTestOneInput(dummy_input, 1);
+
   time_t unit_time_secs;
   int num_runs = 0;
   while (__afl_persistent_loop(N)) {




More information about the llvm-commits mailing list