diff options
author | Vitaly Buka <vitalybuka@google.com> | 2016-06-14 20:42:05 +0000 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2016-06-14 20:42:05 +0000 |
commit | 4b73cc88bf6bbb90b0bb5d6642c1fe91ae7abbff (patch) | |
tree | 84932821191db68c633a2d5b4d9a6732fbdb7632 /llvm/lib/Fuzzer/afl/afl_driver.cpp | |
parent | bf3e6e5bb40c43b9826e33ea5b3376f7da20e4cf (diff) | |
download | bcm5719-llvm-4b73cc88bf6bbb90b0bb5d6642c1fe91ae7abbff.tar.gz bcm5719-llvm-4b73cc88bf6bbb90b0bb5d6642c1fe91ae7abbff.zip |
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: 272706
Diffstat (limited to 'llvm/lib/Fuzzer/afl/afl_driver.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/afl/afl_driver.cpp | 21 |
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 63aebab469c..228317ca9e3 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; |