diff options
| author | Kostya Serebryany <kcc@google.com> | 2019-05-10 00:59:32 +0000 |
|---|---|---|
| committer | Kostya Serebryany <kcc@google.com> | 2019-05-10 00:59:32 +0000 |
| commit | da96d92175f716ba2dd219f937bb26bdea126cbc (patch) | |
| tree | b81c5be9c2b30e9015f293f87b7c4f6462b470a0 /compiler-rt/lib/fuzzer | |
| parent | 2f67cbb62c988d50a3552f4b11cc5b8b4031d093 (diff) | |
| download | bcm5719-llvm-da96d92175f716ba2dd219f937bb26bdea126cbc.tar.gz bcm5719-llvm-da96d92175f716ba2dd219f937bb26bdea126cbc.zip | |
[libFuzzer] small refactoring in the driver; dummy implementation of collect_data_flow; attempt to fix the windows bot
llvm-svn: 360399
Diffstat (limited to 'compiler-rt/lib/fuzzer')
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp | 9 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.h | 4 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerDriver.cpp | 50 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerFlags.def | 2 |
4 files changed, 44 insertions, 21 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp b/compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp index 50ffa98b9ab..466312f72be 100644 --- a/compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp @@ -14,6 +14,7 @@ #include <cstdlib> #include <fstream> +#include <numeric> #include <sstream> #include <string> #include <vector> @@ -195,5 +196,13 @@ void DataFlowTrace::Init(const std::string &DirPath, NumTraceFiles, NumFunctions, NumTracesWithFocusFunction); } +int CollectDataFlow(const std::string &DFTBinary, const std::string &DirPath, + const Vector<std::string> &CorpusDirs, + const Vector<std::string> &ExtraSeeds) { + Printf("INFO: collecting data flow. DFTBinary: %s DirPath: %s\n", + DFTBinary.c_str(), DirPath.c_str()); + return 0; +} + } // namespace fuzzer diff --git a/compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.h b/compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.h index 405845126d1..a45cb5819e7 100644 --- a/compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.h +++ b/compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.h @@ -36,6 +36,10 @@ namespace fuzzer { +int CollectDataFlow(const std::string &DFTBinary, const std::string &DirPath, + const Vector<std::string> &CorpusDirs, + const Vector<std::string> &ExtraSeeds); + class BlockCoverage { public: bool AppendCoverage(std::istream &IN); diff --git a/compiler-rt/lib/fuzzer/FuzzerDriver.cpp b/compiler-rt/lib/fuzzer/FuzzerDriver.cpp index b9c89274703..7a963ad6668 100644 --- a/compiler-rt/lib/fuzzer/FuzzerDriver.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerDriver.cpp @@ -561,6 +561,29 @@ int AnalyzeDictionary(Fuzzer *F, const Vector<Unit>& Dict, return 0; } +Vector<std::string> ParseSeedInuts(const char *seed_inputs) { + // Parse -seed_inputs=file1,file2,... or -seed_inputs=@seed_inputs_file + Vector<std::string> Files; + if (!seed_inputs) return Files; + std::string SeedInputs; + if (Flags.seed_inputs[0] == '@') + SeedInputs = FileToString(Flags.seed_inputs + 1); // File contains list. + else + SeedInputs = Flags.seed_inputs; // seed_inputs contains the list. + if (SeedInputs.empty()) { + Printf("seed_inputs is empty or @file does not exist.\n"); + exit(1); + } + // Parse SeedInputs. + size_t comma_pos = 0; + while ((comma_pos = SeedInputs.find_last_of(',')) != std::string::npos) { + Files.push_back(SeedInputs.substr(comma_pos + 1)); + SeedInputs = SeedInputs.substr(0, comma_pos); + } + Files.push_back(SeedInputs); + return Files; +} + int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) { using namespace fuzzer; assert(argc && argv && "Argument pointers cannot be nullptr"); @@ -663,6 +686,8 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) { Options.FeaturesDir = Flags.features_dir; Options.LazyCounters = Flags.lazy_counters; + auto ExtraSeedFiles = ParseSeedInuts(Flags.seed_inputs); + unsigned Seed = Flags.seed; // Initialize Seed. if (Seed == 0) @@ -671,6 +696,10 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) { if (Flags.verbosity) Printf("INFO: Seed: %u\n", Seed); + if (Flags.collect_data_flow) + return CollectDataFlow(Flags.collect_data_flow, Flags.data_flow_trace, + *Inputs, ExtraSeedFiles); + Random Rand(Seed); auto *MD = new MutationDispatcher(Rand, Options); auto *Corpus = new InputCorpus(Options.OutputCorpus); @@ -763,27 +792,6 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) { exit(0); } - // Parse -seed_inputs=file1,file2,... or -seed_inputs=@seed_inputs_file - Vector<std::string> ExtraSeedFiles; - if (Flags.seed_inputs) { - std::string SeedInputs; - if (Flags.seed_inputs[0] == '@') - SeedInputs = FileToString(Flags.seed_inputs + 1); // File contains list. - else - SeedInputs = Flags.seed_inputs; // seed_inputs contains the list. - if (SeedInputs.empty()) { - Printf("seed_inputs is empty or @file does not exist.\n"); - exit(1); - } - // Parse SeedInputs. - size_t comma_pos = 0; - while ((comma_pos = SeedInputs.find_last_of(',')) != std::string::npos) { - ExtraSeedFiles.push_back(SeedInputs.substr(comma_pos + 1)); - SeedInputs = SeedInputs.substr(0, comma_pos); - } - ExtraSeedFiles.push_back(SeedInputs); - } - F->Loop(*Inputs, ExtraSeedFiles); if (Flags.verbosity) diff --git a/compiler-rt/lib/fuzzer/FuzzerFlags.def b/compiler-rt/lib/fuzzer/FuzzerFlags.def index 81d3f077e64..71f49902247 100644 --- a/compiler-rt/lib/fuzzer/FuzzerFlags.def +++ b/compiler-rt/lib/fuzzer/FuzzerFlags.def @@ -158,3 +158,5 @@ FUZZER_FLAG_STRING(focus_function, "Experimental. " FUZZER_FLAG_INT(analyze_dict, 0, "Experimental") FUZZER_DEPRECATED_FLAG(use_clang_coverage) FUZZER_FLAG_STRING(data_flow_trace, "Experimental: use the data flow trace") +FUZZER_FLAG_STRING(collect_data_flow, + "Experimental: collect the data flow trace") |

