diff options
Diffstat (limited to 'llvm/lib/Fuzzer')
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerIO.cpp | 4 | ||||
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerIO.h | 2 | ||||
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerIOPosix.cpp | 8 | ||||
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerIOWindows.cpp | 8 |
4 files changed, 20 insertions, 2 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerIO.cpp b/llvm/lib/Fuzzer/FuzzerIO.cpp index eda8e877293..45445fa3ba4 100644 --- a/llvm/lib/Fuzzer/FuzzerIO.cpp +++ b/llvm/lib/Fuzzer/FuzzerIO.cpp @@ -97,13 +97,13 @@ void DupAndCloseStderr() { OutputFile = NewOutputFile; if (EF->__sanitizer_set_report_fd) EF->__sanitizer_set_report_fd(reinterpret_cast<void *>(OutputFd)); - CloseFile(2); + DiscardOutput(2); } } } void CloseStdout() { - CloseFile(1); + DiscardOutput(1); } void Printf(const char *Fmt, ...) { diff --git a/llvm/lib/Fuzzer/FuzzerIO.h b/llvm/lib/Fuzzer/FuzzerIO.h index 17cf2ab6ac1..1f79f3632ba 100644 --- a/llvm/lib/Fuzzer/FuzzerIO.h +++ b/llvm/lib/Fuzzer/FuzzerIO.h @@ -64,6 +64,8 @@ int DuplicateFile(int Fd); void RemoveFile(const std::string &Path); +void DiscardOutput(int Fd); + } // namespace fuzzer #endif // LLVM_FUZZER_IO_H diff --git a/llvm/lib/Fuzzer/FuzzerIOPosix.cpp b/llvm/lib/Fuzzer/FuzzerIOPosix.cpp index 494ec9e6c83..2dc2c61b999 100644 --- a/llvm/lib/Fuzzer/FuzzerIOPosix.cpp +++ b/llvm/lib/Fuzzer/FuzzerIOPosix.cpp @@ -75,6 +75,14 @@ void RemoveFile(const std::string &Path) { unlink(Path.c_str()); } +void DiscardOutput(int Fd) { + FILE* Temp = fopen("/dev/null", "w"); + if (!Temp) + return; + dup2(fileno(Temp), Fd); + fclose(Temp); +} + std::string DirName(const std::string &FileName) { char *Tmp = new char[FileName.size() + 1]; memcpy(Tmp, FileName.c_str(), FileName.size() + 1); diff --git a/llvm/lib/Fuzzer/FuzzerIOWindows.cpp b/llvm/lib/Fuzzer/FuzzerIOWindows.cpp index 983cb6c2e4a..1d82f416272 100644 --- a/llvm/lib/Fuzzer/FuzzerIOWindows.cpp +++ b/llvm/lib/Fuzzer/FuzzerIOWindows.cpp @@ -141,6 +141,14 @@ void RemoveFile(const std::string &Path) { _unlink(Path.c_str()); } +void DiscardOutput(int Fd) { + FILE* Temp = fopen("nul", "w"); + if (!Temp) + return; + _dup2(_fileno(Temp), Fd); + fclose(Temp); +} + static bool IsSeparator(char C) { return C == '\\' || C == '/'; } |

