Skip to content

Commit da96d92

Browse files
committed
[libFuzzer] small refactoring in the driver; dummy implementation of collect_data_flow; attempt to fix the windows bot
llvm-svn: 360399
1 parent 2f67cbb commit da96d92

File tree

4 files changed

+44
-21
lines changed

4 files changed

+44
-21
lines changed

compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <cstdlib>
1616
#include <fstream>
17+
#include <numeric>
1718
#include <sstream>
1819
#include <string>
1920
#include <vector>
@@ -195,5 +196,13 @@ void DataFlowTrace::Init(const std::string &DirPath,
195196
NumTraceFiles, NumFunctions, NumTracesWithFocusFunction);
196197
}
197198

199+
int CollectDataFlow(const std::string &DFTBinary, const std::string &DirPath,
200+
const Vector<std::string> &CorpusDirs,
201+
const Vector<std::string> &ExtraSeeds) {
202+
Printf("INFO: collecting data flow. DFTBinary: %s DirPath: %s\n",
203+
DFTBinary.c_str(), DirPath.c_str());
204+
return 0;
205+
}
206+
198207
} // namespace fuzzer
199208

compiler-rt/lib/fuzzer/FuzzerDataFlowTrace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636

3737
namespace fuzzer {
3838

39+
int CollectDataFlow(const std::string &DFTBinary, const std::string &DirPath,
40+
const Vector<std::string> &CorpusDirs,
41+
const Vector<std::string> &ExtraSeeds);
42+
3943
class BlockCoverage {
4044
public:
4145
bool AppendCoverage(std::istream &IN);

compiler-rt/lib/fuzzer/FuzzerDriver.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,29 @@ int AnalyzeDictionary(Fuzzer *F, const Vector<Unit>& Dict,
561561
return 0;
562562
}
563563

564+
Vector<std::string> ParseSeedInuts(const char *seed_inputs) {
565+
// Parse -seed_inputs=file1,file2,... or -seed_inputs=@seed_inputs_file
566+
Vector<std::string> Files;
567+
if (!seed_inputs) return Files;
568+
std::string SeedInputs;
569+
if (Flags.seed_inputs[0] == '@')
570+
SeedInputs = FileToString(Flags.seed_inputs + 1); // File contains list.
571+
else
572+
SeedInputs = Flags.seed_inputs; // seed_inputs contains the list.
573+
if (SeedInputs.empty()) {
574+
Printf("seed_inputs is empty or @file does not exist.\n");
575+
exit(1);
576+
}
577+
// Parse SeedInputs.
578+
size_t comma_pos = 0;
579+
while ((comma_pos = SeedInputs.find_last_of(',')) != std::string::npos) {
580+
Files.push_back(SeedInputs.substr(comma_pos + 1));
581+
SeedInputs = SeedInputs.substr(0, comma_pos);
582+
}
583+
Files.push_back(SeedInputs);
584+
return Files;
585+
}
586+
564587
int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) {
565588
using namespace fuzzer;
566589
assert(argc && argv && "Argument pointers cannot be nullptr");
@@ -663,6 +686,8 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) {
663686
Options.FeaturesDir = Flags.features_dir;
664687
Options.LazyCounters = Flags.lazy_counters;
665688

689+
auto ExtraSeedFiles = ParseSeedInuts(Flags.seed_inputs);
690+
666691
unsigned Seed = Flags.seed;
667692
// Initialize Seed.
668693
if (Seed == 0)
@@ -671,6 +696,10 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) {
671696
if (Flags.verbosity)
672697
Printf("INFO: Seed: %u\n", Seed);
673698

699+
if (Flags.collect_data_flow)
700+
return CollectDataFlow(Flags.collect_data_flow, Flags.data_flow_trace,
701+
*Inputs, ExtraSeedFiles);
702+
674703
Random Rand(Seed);
675704
auto *MD = new MutationDispatcher(Rand, Options);
676705
auto *Corpus = new InputCorpus(Options.OutputCorpus);
@@ -763,27 +792,6 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) {
763792
exit(0);
764793
}
765794

766-
// Parse -seed_inputs=file1,file2,... or -seed_inputs=@seed_inputs_file
767-
Vector<std::string> ExtraSeedFiles;
768-
if (Flags.seed_inputs) {
769-
std::string SeedInputs;
770-
if (Flags.seed_inputs[0] == '@')
771-
SeedInputs = FileToString(Flags.seed_inputs + 1); // File contains list.
772-
else
773-
SeedInputs = Flags.seed_inputs; // seed_inputs contains the list.
774-
if (SeedInputs.empty()) {
775-
Printf("seed_inputs is empty or @file does not exist.\n");
776-
exit(1);
777-
}
778-
// Parse SeedInputs.
779-
size_t comma_pos = 0;
780-
while ((comma_pos = SeedInputs.find_last_of(',')) != std::string::npos) {
781-
ExtraSeedFiles.push_back(SeedInputs.substr(comma_pos + 1));
782-
SeedInputs = SeedInputs.substr(0, comma_pos);
783-
}
784-
ExtraSeedFiles.push_back(SeedInputs);
785-
}
786-
787795
F->Loop(*Inputs, ExtraSeedFiles);
788796

789797
if (Flags.verbosity)

compiler-rt/lib/fuzzer/FuzzerFlags.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,5 @@ FUZZER_FLAG_STRING(focus_function, "Experimental. "
158158
FUZZER_FLAG_INT(analyze_dict, 0, "Experimental")
159159
FUZZER_DEPRECATED_FLAG(use_clang_coverage)
160160
FUZZER_FLAG_STRING(data_flow_trace, "Experimental: use the data flow trace")
161+
FUZZER_FLAG_STRING(collect_data_flow,
162+
"Experimental: collect the data flow trace")

0 commit comments

Comments
 (0)