[PATCH] D29548: [libFuzzer] Fix close_fd_mask.
Marcos Pividori via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 4 14:14:17 PST 2017
mpividori created this revision.
For Windows, sanitizers work with Handles, not with posix file descriptors, because they use the windows-specific API. So we need to convert the fds to handles before passing them to the sanitizer library.
After this change, `close_fd_mask` is fixed for Windows (this fix some tests too).
https://reviews.llvm.org/D29548
Files:
lib/Fuzzer/FuzzerIO.cpp
lib/Fuzzer/FuzzerIO.h
lib/Fuzzer/FuzzerIOPosix.cpp
lib/Fuzzer/FuzzerIOWindows.cpp
Index: lib/Fuzzer/FuzzerIOWindows.cpp
===================================================================
--- lib/Fuzzer/FuzzerIOWindows.cpp
+++ lib/Fuzzer/FuzzerIOWindows.cpp
@@ -149,6 +149,10 @@
fclose(Temp);
}
+int GetHandleFromFd(int fd) {
+ return _get_osfhandle(fd);
+}
+
static bool IsSeparator(char C) {
return C == '\\' || C == '/';
}
Index: lib/Fuzzer/FuzzerIOPosix.cpp
===================================================================
--- lib/Fuzzer/FuzzerIOPosix.cpp
+++ lib/Fuzzer/FuzzerIOPosix.cpp
@@ -83,6 +83,10 @@
fclose(Temp);
}
+int GetHandleFromFd(int fd) {
+ return fd;
+}
+
std::string DirName(const std::string &FileName) {
char *Tmp = new char[FileName.size() + 1];
memcpy(Tmp, FileName.c_str(), FileName.size() + 1);
Index: lib/Fuzzer/FuzzerIO.h
===================================================================
--- lib/Fuzzer/FuzzerIO.h
+++ lib/Fuzzer/FuzzerIO.h
@@ -69,6 +69,8 @@
void DiscardOutput(int Fd);
+int GetHandleFromFd(int fd);
+
} // namespace fuzzer
#endif // LLVM_FUZZER_IO_H
Index: lib/Fuzzer/FuzzerIO.cpp
===================================================================
--- lib/Fuzzer/FuzzerIO.cpp
+++ lib/Fuzzer/FuzzerIO.cpp
@@ -96,7 +96,8 @@
if (NewOutputFile) {
OutputFile = NewOutputFile;
if (EF->__sanitizer_set_report_fd)
- EF->__sanitizer_set_report_fd(reinterpret_cast<void *>(OutputFd));
+ EF->__sanitizer_set_report_fd(reinterpret_cast<void *>(
+ GetHandleFromFd(OutputFd)));
DiscardOutput(2);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29548.87108.patch
Type: text/x-patch
Size: 1553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170204/c6b0c927/attachment.bin>
More information about the llvm-commits
mailing list