Skip to content

Commit

Permalink
implement coverage dump
Browse files Browse the repository at this point in the history
  • Loading branch information
ifratric committed Sep 5, 2022
1 parent 0b41d4d commit 6134ff1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ void Fuzzer::ParseOptions(int argc, char **argv) {
incremental_coverage = GetBinaryOption("-incremental_coverage", argc, argv, true);

add_all_inputs = GetBinaryOption("-add_all_inputs", argc, argv, false);

dump_coverage = GetBinaryOption("-dump_coverage", argc, argv, false);
}

void Fuzzer::SetupDirectories() {
Expand Down Expand Up @@ -807,6 +809,11 @@ void Fuzzer::RunFuzzerThread(ThreadContext *tc) {
}
}

void Fuzzer::DumpCoverage() {
std::string out_file = DirJoin(out_dir, "coverage.txt");
WriteCoverage(fuzzer_coverage, out_file.c_str());
}

void Fuzzer::SaveState(ThreadContext *tc) {
// don't save during input sample processing
if(state == INPUT_SAMPLE_PROCESSING) return;
Expand Down Expand Up @@ -843,6 +850,8 @@ void Fuzzer::SaveState(ThreadContext *tc) {
fwrite(&sentry, sizeof(sentry), 1, fp);

fclose(fp);

if(dump_coverage) DumpCoverage();

coverage_mutex.Unlock();
output_mutex.Unlock();
Expand Down
3 changes: 3 additions & 0 deletions fuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class Fuzzer {

void SaveState(ThreadContext *tc);
void RestoreState(ThreadContext *tc);
void DumpCoverage();

std::string in_dir;
std::string out_dir;
Expand Down Expand Up @@ -252,6 +253,8 @@ class Fuzzer {

bool add_all_inputs;

bool dump_coverage;

Mutex crash_mutex;
std::unordered_map<std::string, int> unique_crashes;

Expand Down

0 comments on commit 6134ff1

Please sign in to comment.