[PATCH] D29548: [libFuzzer] Fix close_fd_mask.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 4 14:58:09 PST 2017
This is incorrect, HANDLE is an alias for void*, by returning an integer
you are truncating the high 32 buts of the value. But then you just cast it
back to a void* anyway, so i think you should just return void* from the
start. On the posix side you will need to return the fd as a void* as well.
Make sure to use static_cast and not reinterpret_cast, in case int is not
the same size as void*
On Sat, Feb 4, 2017 at 2:14 PM Marcos Pividori via Phabricator <
reviews at reviews.llvm.org> wrote:
> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170204/8b9fd7df/attachment.html>
More information about the llvm-commits
mailing list