[PATCH] D41193: [libFuzzer] Add dummy call of LLVMFuzzerTestOneInput to afl_driver.

Jonathan Metzman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 12:19:28 PST 2017


metzman created this revision.
Herald added subscribers: Sanitizers, llvm-commits.

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.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D41193

Files:
  lib/fuzzer/afl/afl_driver.cpp


Index: lib/fuzzer/afl/afl_driver.cpp
===================================================================
--- lib/fuzzer/afl/afl_driver.cpp
+++ lib/fuzzer/afl/afl_driver.cpp
@@ -88,7 +88,7 @@
 // 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();                                                                   \
   }
 
@@ -298,6 +298,12 @@
 
   __afl_manual_init();
 
+  // Call LLVMFuzzerTestOneInput here so that initialization is done before
+  // AFL considers it code covered by a particular input. Don't do this before
+  // __afl_manual_init() or some targets may break.
+  uint8_t dummy_input[1] = {0};
+  LLVMFuzzerTestOneInput(dummy_input, 1);
+
   int N = 1000;
   if (argc == 2 && argv[1][0] == '-')
       N = atoi(argv[1] + 1);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41193.126807.patch
Type: text/x-patch
Size: 1112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171213/bab62c1a/attachment.bin>


More information about the llvm-commits mailing list