Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 22d6013

Browse files
committed
[libFuzzer] add -artifact_prefix flag
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249807 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 634b8b0 commit 22d6013

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

docs/LibFuzzer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The most important flags are::
7171
use_traces 0 Experimental: use instruction traces
7272
only_ascii 0 If 1, generate only ASCII (isprint+isspace) inputs.
7373
test_single_input "" Use specified file content as test input. Test will be run only once. Useful for debugging a particular case.
74-
74+
artifact_prefix "" Write fuzzing artifacts (crash, timeout, or slow inputs) as $(artifact_prefix)file
7575

7676
For the full list of flags run the fuzzer binary with ``-help=1``.
7777

lib/Fuzzer/FuzzerDriver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ int FuzzerDriver(const std::vector<std::string> &Args,
270270
Options.SyncCommand = Flags.sync_command;
271271
Options.SyncTimeout = Flags.sync_timeout;
272272
Options.ReportSlowUnits = Flags.report_slow_units;
273+
if (Flags.artifact_prefix)
274+
Options.ArtifactPrefix = Flags.artifact_prefix;
273275
if (Flags.dict)
274276
if (!ParseDictionaryFile(FileToString(Flags.dict), &Options.Dictionary))
275277
return 1;

lib/Fuzzer/FuzzerFlags.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@ FUZZER_FLAG_INT(tbm_depth, 5, "Apply at most this number of consecutive"
6565
FUZZER_FLAG_INT(tbm_width, 5, "Apply at most this number of independent"
6666
"trace-based-mutations (tbm)")
6767
FUZZER_FLAG_STRING(test_single_input, "Use specified file as test input.")
68+
FUZZER_FLAG_STRING(artifact_prefix, "Write fuzzing artifacts (crash, "
69+
"timeout, or slow inputs) as "
70+
"$(artifact_prefix)file")

lib/Fuzzer/FuzzerInternal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class Fuzzer {
9090
int TBMWidth = 10;
9191
std::string OutputCorpus;
9292
std::string SyncCommand;
93+
std::string ArtifactPrefix = "./";
9394
std::vector<std::string> Tokens;
9495
std::vector<Unit> Dictionary;
9596
};

lib/Fuzzer/FuzzerLoop.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,10 @@ void Fuzzer::WriteToOutputCorpus(const Unit &U) {
236236
}
237237

238238
void Fuzzer::WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix) {
239-
std::string Path = Prefix + Hash(U);
239+
std::string Path = Options.ArtifactPrefix + Prefix + Hash(U);
240240
WriteToFile(U, Path);
241-
Printf("Test unit written to %s\n", Path.c_str());
241+
Printf("artifact_prefix='%s'; Test unit written to %s\n",
242+
Options.ArtifactPrefix.c_str(), Path.c_str());
242243
if (U.size() <= kMaxUnitSizeToPrint) {
243244
Printf("Base64: ");
244245
PrintFileAsBase64(Path);

lib/Fuzzer/test/fuzzer.test

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ RUN: LLVMFuzzer-SimpleTest -test_single_input=%S/hi.txt 2>&1 | FileCheck %s
55

66
RUN: not LLVMFuzzer-InfiniteTest -timeout=2 2>&1 | FileCheck %s --check-prefix=InfiniteTest
77
InfiniteTest: ALARM: working on the last Unit for
8-
InfiniteTest: Test unit written to timeout-
8+
InfiniteTest: Test unit written to ./timeout-
99

1010
RUN: LLVMFuzzer-SimpleCmpTest -max_total_time=1 2>&1 | FileCheck %s --check-prefix=MaxTotalTime
1111
MaxTotalTime: Done {{.*}} runs in {{.}} second(s)
1212

1313
RUN: not LLVMFuzzer-TimeoutTest -timeout=5 2>&1 | FileCheck %s --check-prefix=TimeoutTest
1414
TimeoutTest: ALARM: working on the last Unit for
15-
TimeoutTest: Test unit written to timeout-
15+
TimeoutTest: Test unit written to ./timeout-
1616

1717
RUN: not LLVMFuzzer-NullDerefTest 2>&1 | FileCheck %s --check-prefix=NullDerefTest
18-
NullDerefTest: Test unit written to crash-
18+
NullDerefTest: Test unit written to ./crash-
19+
RUN: not LLVMFuzzer-NullDerefTest -artifact_prefix=ZZZ 2>&1 | FileCheck %s --check-prefix=NullDerefTestPrefix
20+
NullDerefTestPrefix: Test unit written to ZZZcrash-
1921

2022
#not LLVMFuzzer-FullCoverageSetTest -timeout=15 -seed=1 -mutate_depth=2 -use_full_coverage_set=1 2>&1 | FileCheck %s
2123

0 commit comments

Comments
 (0)