summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/FuzzerIO.h
diff options
context:
space:
mode:
authorMarcos Pividori <mpividori@google.com>2017-01-22 01:58:45 +0000
committerMarcos Pividori <mpividori@google.com>2017-01-22 01:58:45 +0000
commit61ecfc0be3dd4c51e2c61fa9a0c277c8b42c1131 (patch)
tree75bd7cb230d0a309951743e4245be2518fd83cba /llvm/lib/Fuzzer/FuzzerIO.h
parentc0533612bc47163ba22abde7c9f6f96fc4124c2f (diff)
downloadbcm5719-llvm-61ecfc0be3dd4c51e2c61fa9a0c277c8b42c1131.tar.gz
bcm5719-llvm-61ecfc0be3dd4c51e2c61fa9a0c277c8b42c1131.zip
[libFuzzer] Avoid undefined behavior, properly discard output to stdout/stderr.
Fix libFuzzer when setting -close_fd_mask to a non-zero value. In previous implementation, libFuzzer closes the file descriptors for stdout/stderr. This has some disavantages: For `fuzzer-fdmask.test`, we write directly to stdout and stderr using the file streams stdout and stderr, after the file descriptors are closed, which is undefined behavior. In Windows, in particular, this was making the test fail. Also, if we close stdout and we open a new file in libFuzzer, we get the file descriptor 1, which could generate problem if some code assumes file descriptors refers to stdout and works directly writing to the file descriptor 1, but it will be writing to the opened file (for example using std::cout). Instead of closing the file descriptors, I redirect the output to /dev/null on linux and nul on Windows. Differential Revision: https://reviews.llvm.org/D28718 llvm-svn: 292743
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerIO.h')
-rw-r--r--llvm/lib/Fuzzer/FuzzerIO.h2
1 files changed, 2 insertions, 0 deletions
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
OpenPOWER on IntegriCloud