diff options
| author | Marco Vanotti <mvanotti@google.com> | 2019-10-29 15:38:51 -0700 |
|---|---|---|
| committer | Marco Vanotti <mvanotti@google.com> | 2019-11-21 16:56:05 -0800 |
| commit | e5b603a4c32044932c3a1d26ccbc7d43fec939d5 (patch) | |
| tree | 35447dd82e938463586d700c1d9abec7379a6f1f /compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp | |
| parent | b2e6c2b9954ba9f9b68b8394790f6cae35aea58e (diff) | |
| download | bcm5719-llvm-e5b603a4c32044932c3a1d26ccbc7d43fec939d5.tar.gz bcm5719-llvm-e5b603a4c32044932c3a1d26ccbc7d43fec939d5.zip | |
[libFuzzer] don't use /dev/null for DiscardOuput in Fuchsia.
Summary:
This commit moves the `DiscardOutput` function in FuzzerIO to
FuzzerUtil, so fuchsia can have its own specialized version.
In fuchsia, accessing `/dev/null` is not supported, and there's nothing
similar to a file that discards everything that is written to it. The
way of doing something similar in fuchsia is by using `fdio_null_create`
and binding that to a file descriptor with `fdio_bind_to_fd`.
This change should fix one of the issues with the `-close_fd_mask` flag
in libfuzzer, in which closing stdout was not working due to
`fopen("/dev/null", "w")` returning `NULL`.
Reviewers: kcc, aarongreen
Subscribers: #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D69593
Diffstat (limited to 'compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp')
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp index 171db23570c..d449bc248f0 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp @@ -17,6 +17,7 @@ #include <stdlib.h> #include <string.h> #include <sys/wait.h> +#include <unistd.h> // There is no header for this on macOS so declare here extern "C" char **environ; @@ -156,6 +157,14 @@ int ExecuteCommand(const Command &Cmd) { return ProcessStatus; } +void DiscardOutput(int Fd) { + FILE* Temp = fopen("/dev/null", "w"); + if (!Temp) + return; + dup2(fileno(Temp), Fd); + fclose(Temp); +} + } // namespace fuzzer #endif // LIBFUZZER_APPLE |

