[PATCH] D13752: [LibFuzzer] Do not write crash unit file for single input
Mike Aizatsky via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 14:06:48 PDT 2015
aizatsky updated this revision to Diff 37640.
aizatsky added a comment.
- handling bad file
http://reviews.llvm.org/D13752
Files:
lib/Fuzzer/FuzzerDriver.cpp
lib/Fuzzer/FuzzerIO.cpp
lib/Fuzzer/FuzzerInternal.h
lib/Fuzzer/FuzzerLoop.cpp
lib/Fuzzer/test/fuzzer.test
Index: lib/Fuzzer/test/fuzzer.test
===================================================================
--- lib/Fuzzer/test/fuzzer.test
+++ lib/Fuzzer/test/fuzzer.test
@@ -1,7 +1,8 @@
CHECK: BINGO
RUN: LLVMFuzzer-SimpleTest 2>&1 | FileCheck %s
-RUN: LLVMFuzzer-SimpleTest -test_single_input=%S/hi.txt 2>&1 | FileCheck %s
+RUN: not LLVMFuzzer-NullDerefTest -test_single_input=%S/hi.txt 2>&1 | FileCheck %s --check-prefix=SingleInput
+SingleInput-NOT: Test unit written to ./crash-
RUN: not LLVMFuzzer-InfiniteTest -timeout=2 2>&1 | FileCheck %s --check-prefix=InfiniteTest
InfiniteTest: ALARM: working on the last Unit for
@@ -14,6 +15,10 @@
TimeoutTest: ALARM: working on the last Unit for
TimeoutTest: Test unit written to ./timeout-
+RUN: not LLVMFuzzer-TimeoutTest -timeout=5 -test_single_input=%S/hi.txt 2>&1 | FileCheck %s --check-prefix=SingleInputTimeoutTest
+SingleInputTimeoutTest: ALARM: working on the last Unit for
+SingleInputTimeoutTest-NOT: Test unit written to ./timeout-
+
RUN: not LLVMFuzzer-NullDerefTest 2>&1 | FileCheck %s --check-prefix=NullDerefTest
NullDerefTest: Test unit written to ./crash-
RUN: not LLVMFuzzer-NullDerefTest -artifact_prefix=ZZZ 2>&1 | FileCheck %s --check-prefix=NullDerefTestPrefix
Index: lib/Fuzzer/FuzzerLoop.cpp
===================================================================
--- lib/Fuzzer/FuzzerLoop.cpp
+++ lib/Fuzzer/FuzzerLoop.cpp
@@ -237,6 +237,8 @@
}
void Fuzzer::WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix) {
+ if (!Options.SaveUnits)
+ return;
std::string Path = Options.ArtifactPrefix + Prefix + Hash(U);
WriteToFile(U, Path);
Printf("artifact_prefix='%s'; Test unit written to %s\n",
Index: lib/Fuzzer/FuzzerInternal.h
===================================================================
--- lib/Fuzzer/FuzzerInternal.h
+++ lib/Fuzzer/FuzzerInternal.h
@@ -93,6 +93,7 @@
std::string ArtifactPrefix = "./";
std::vector<std::string> Tokens;
std::vector<Unit> Dictionary;
+ bool SaveUnits = true;
};
Fuzzer(UserSuppliedFuzzer &USF, FuzzingOptions Options);
void AddToCorpus(const Unit &U) { Corpus.push_back(U); }
Index: lib/Fuzzer/FuzzerIO.cpp
===================================================================
--- lib/Fuzzer/FuzzerIO.cpp
+++ lib/Fuzzer/FuzzerIO.cpp
@@ -49,6 +49,10 @@
Unit FileToVector(const std::string &Path) {
std::ifstream T(Path);
+ if (!T) {
+ Printf("No such directory: %s; exiting\n", Path.c_str());
+ exit(1);
+ }
return Unit((std::istreambuf_iterator<char>(T)),
std::istreambuf_iterator<char>());
}
Index: lib/Fuzzer/FuzzerDriver.cpp
===================================================================
--- lib/Fuzzer/FuzzerDriver.cpp
+++ lib/Fuzzer/FuzzerDriver.cpp
@@ -277,12 +277,17 @@
return 1;
if (Flags.verbosity > 0 && !Options.Dictionary.empty())
Printf("Dictionary: %zd entries\n", Options.Dictionary.size());
+ Options.SaveUnits = !Flags.test_single_input;
Fuzzer F(USF, Options);
if (Flags.apply_tokens)
return ApplyTokens(F, Flags.apply_tokens);
+ // Timer
+ if (Flags.timeout > 0)
+ SetTimer(Flags.timeout / 2 + 1);
+
if (Flags.test_single_input)
return RunOneTest(&F, Flags.test_single_input);
@@ -294,10 +299,6 @@
Printf("Seed: %u\n", Seed);
USF.GetRand().ResetSeed(Seed);
- // Timer
- if (Flags.timeout > 0)
- SetTimer(Flags.timeout / 2 + 1);
-
if (Flags.verbosity >= 2) {
Printf("Tokens: {");
for (auto &T : Options.Tokens)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13752.37640.patch
Type: text/x-patch
Size: 3515 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151016/3031c278/attachment.bin>
More information about the llvm-commits
mailing list