summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/afl/afl_driver.cpp
diff options
context:
space:
mode:
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 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;
OpenPOWER on IntegriCloud