[PATCH] D73813: [libFuzzer] Make dataflow and focus functions more user friendly.

Max Moroz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 3 08:48:50 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGad7b908b4ef9: [libFuzzer] Make dataflow and focus functions more user friendly. (authored by Dor1s).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73813/new/

https://reviews.llvm.org/D73813

Files:
  compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp
  compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
  compiler-rt/test/fuzzer/dataflow.test
  compiler-rt/test/fuzzer/focus-function.test
  compiler-rt/test/fuzzer/target-function.test


Index: compiler-rt/test/fuzzer/focus-function.test
===================================================================
--- compiler-rt/test/fuzzer/focus-function.test
+++ compiler-rt/test/fuzzer/focus-function.test
@@ -10,9 +10,9 @@
 FOCUS_NONE-NOT: INFO: Focus function is set to
 FOCUS_NONE-NOT: INFO: {{.*}} inputs touch the focus function
 
-RUN: %t-exe -runs=100 -focus_function=WRONG 2>&1 | FileCheck %s --check-prefix=FOCUS_WRONG
+RUN: not %t-exe -runs=100 -focus_function=WRONG 2>&1 | FileCheck %s --check-prefix=FOCUS_WRONG
 FOCUS_WRONG-NOT: INFO: Focus function is set to
-FOCUS_WRONG: INFO: 0/1 inputs touch the focus function
+FOCUS_WRONG: ERROR: Failed to set focus function
 
 RUN: %t-exe -runs=100 -focus_function=f0 2>&1 | FileCheck %s --check-prefix=FOCUS_F0
 FOCUS_F0: INFO: Focus function is set to 'f0'
Index: compiler-rt/test/fuzzer/dataflow.test
===================================================================
--- compiler-rt/test/fuzzer/dataflow.test
+++ compiler-rt/test/fuzzer/dataflow.test
@@ -118,3 +118,9 @@
 RUN: rm -rf %t/OUT
 RUN: %t-ThreeFunctionsTest  -collect_data_flow=%t-ThreeFunctionsTestDF -data_flow_trace=%t/OUT %t/IN/very_long_input
 RUN: rm %t/IN/very_long_input
+
+# Test that it fails explicitly when an empty corpus is provided.
+RUN: rm -rf %t/IN && mkdir %t/IN
+RUN: not %t-ThreeFunctionsTest  -collect_data_flow=%t-ThreeFunctionsTestDF -data_flow_trace=%t/OUT %t/IN 2>&1 | FileCheck %s --check-prefix=EMPTY_CORPUS
+
+EMPTY_CORPUS: ERROR: can't collect data flow without corpus provided
Index: compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
===================================================================
--- compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
+++ compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
@@ -240,7 +240,9 @@
 void TracePC::SetFocusFunction(const std::string &FuncName) {
   // This function should be called once.
   assert(!FocusFunctionCounterPtr);
-  if (FuncName.empty())
+  // "auto" is not a valid function name. If this function is called with "auto"
+  // that means the auto focus functionality failed.
+  if (FuncName.empty() || FuncName == "auto")
     return;
   for (size_t M = 0; M < NumModules; M++) {
     auto &PCTE = ModulePCTable[M];
@@ -256,6 +258,10 @@
       return;
     }
   }
+
+  Printf("ERROR: Failed to set focus function. Make sure the function name is "
+         "valid (%s) and symbolization is enabled.\n", FuncName.c_str());
+  exit(1);
 }
 
 bool TracePC::ObservedFocusFunction() {
Index: compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp
===================================================================
--- compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp
+++ compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp
@@ -248,6 +248,11 @@
                     const Vector<SizedFile> &CorporaFiles) {
   Printf("INFO: collecting data flow: bin: %s dir: %s files: %zd\n",
          DFTBinary.c_str(), DirPath.c_str(), CorporaFiles.size());
+  if (CorporaFiles.empty()) {
+    Printf("ERROR: can't collect data flow without corpus provided.");
+    return 1;
+  }
+
   static char DFSanEnv[] = "DFSAN_OPTIONS=fast16labels=1:warn_unimplemented=0";
   putenv(DFSanEnv);
   MkDir(DirPath);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73813.242095.patch
Type: text/x-patch
Size: 3164 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200203/e0b9c77f/attachment.bin>


More information about the llvm-commits mailing list