aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Fuzzer/afl/afl_driver.cpp
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2016-06-16 00:14:42 +0000
committerVitaly Buka <vitalybuka@google.com>2016-06-16 00:14:42 +0000
commitd01720d46d9456fce63f58497f56e106d2311efc (patch)
tree16abb0693268746752db3b3b41eb43a152e11dea /llvm/lib/Fuzzer/afl/afl_driver.cpp
parent4db224e199e9f0903cc1e80c5d3869346ea67b5f (diff)
downloadllvm-d01720d46d9456fce63f58497f56e106d2311efc.zip
llvm-d01720d46d9456fce63f58497f56e106d2311efc.tar.gz
llvm-d01720d46d9456fce63f58497f56e106d2311efc.tar.bz2
Enable libFuzzer's afl_driver to append stderr to a file.
Summary: [libFuzzer] Enable afl_driver to append stderr to a user specified file. Append stderr of afl_driver to the file specified by the environmental variable AFL_DRIVER_STDERR_DUPLICATE_FILENAME if it is set. This lets users see outputs on crashes without rerunning crashing test cases (which won't work for crashes that are difficult to reproduce). Before this patch, stderr would only be sent to afl-fuzz and users would have no way of seeing it. Reviewers: llvm-commits, aizatsky, kcc, vitalybuka Subscribers: vitalybuka Differential Revision: http://reviews.llvm.org/D21194 llvm-svn: 272858
Diffstat (limited to 'llvm/lib/Fuzzer/afl/afl_driver.cpp')
-rw-r--r--llvm/lib/Fuzzer/afl/afl_driver.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/afl/afl_driver.cpp b/llvm/lib/Fuzzer/afl/afl_driver.cpp
index 63aebab..228317c 100644
--- a/llvm/lib/Fuzzer/afl/afl_driver.cpp
+++ b/llvm/lib/Fuzzer/afl/afl_driver.cpp
@@ -60,6 +60,25 @@ static volatile char suppress_warning1 = AFL_DEFER_FORKSVR[0];
static const size_t kMaxAflInputSize = 1 << 20;
static uint8_t AflInputBuf[kMaxAflInputSize];
+// If the user asks us to duplicate stderr, then do it.
+static void maybe_duplicate_stderr() {
+ char* stderr_duplicate_filename =
+ getenv("AFL_DRIVER_STDERR_DUPLICATE_FILENAME");
+
+ if (!stderr_duplicate_filename)
+ return;
+
+ FILE* stderr_duplicate_stream =
+ freopen(stderr_duplicate_filename, "a+", stderr);
+
+ if (!stderr_duplicate_stream) {
+ fprintf(stderr,
+ "Failed to duplicate stderr to AFL_DRIVER_STDERR_DUPLICATE_FILENAME"
+ );
+ abort();
+ }
+}
+
int main(int argc, char **argv) {
fprintf(stderr, "Running in AFl-fuzz mode\nUsage:\n"
"afl-fuzz [afl-flags] %s [N] "
@@ -70,6 +89,8 @@ int main(int argc, char **argv) {
LLVMFuzzerInitialize(&argc, &argv);
// Do any other expensive one-time initialization here.
+ maybe_duplicate_stderr();
+
__afl_manual_init();
int N = 1000;