[PATCH] D27948: [libFuzzer] Diff 37 - [FuzzerSupport] Decouple UtilIO from external Functions.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 19 14:16:09 PST 2016


mpividori created this revision.
mpividori added reviewers: kcc, zturner.
mpividori added a subscriber: llvm-commits.
mpividori set the repository for this revision to rL LLVM.

Repository:
  rL LLVM

https://reviews.llvm.org/D27948

Files:
  lib/Fuzzer/FuzzerDriver.cpp
  lib/Fuzzer/Support/UtilIO.cpp
  lib/Fuzzer/Support/UtilIO.h


Index: lib/Fuzzer/Support/UtilIO.h
===================================================================
--- lib/Fuzzer/Support/UtilIO.h
+++ lib/Fuzzer/Support/UtilIO.h
@@ -40,7 +40,7 @@
 // Returns the name of the dir, similar to the 'dirname' utility.
 std::string DirName(const std::string &FileName);
 
-void DupAndCloseStderr();
+int DupAndCloseStderr();
 
 void CloseStdout();
 
Index: lib/Fuzzer/Support/UtilIO.cpp
===================================================================
--- lib/Fuzzer/Support/UtilIO.cpp
+++ lib/Fuzzer/Support/UtilIO.cpp
@@ -10,8 +10,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "UtilIO.h"
-#include "FuzzerDefs.h"
-#include "FuzzerExtFunctions.h"
 #include <algorithm>
 #include <cstdarg>
 #include <fstream>
@@ -89,17 +87,16 @@
   return DirPath + GetSeparator() + FileName;
 }
 
-void DupAndCloseStderr() {
+int DupAndCloseStderr() {
   int OutputFd = DuplicateFile(2);
   if (OutputFd > 0) {
     FILE *NewOutputFile = OpenFile(OutputFd, "w");
     if (NewOutputFile) {
       OutputFile = NewOutputFile;
-      if (EF->__sanitizer_set_report_fd)
-        EF->__sanitizer_set_report_fd(reinterpret_cast<void *>(OutputFd));
       CloseFile(2);
     }
   }
+  return OutputFd;
 }
 
 void CloseStdout() {
Index: lib/Fuzzer/FuzzerDriver.cpp
===================================================================
--- lib/Fuzzer/FuzzerDriver.cpp
+++ lib/Fuzzer/FuzzerDriver.cpp
@@ -371,8 +371,12 @@
   if (Flags.minimize_crash)
     return MinimizeCrashInput(Args);
 
-  if (Flags.close_fd_mask & 2)
-    DupAndCloseStderr();
+  if (Flags.close_fd_mask & 2) {
+    int FD = DupAndCloseStderr();
+    if (FD > 0 && EF->__sanitizer_set_report_fd)
+      EF->__sanitizer_set_report_fd(reinterpret_cast<void *>(FD));
+  }
+
   if (Flags.close_fd_mask & 1)
     CloseStdout();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27948.82011.patch
Type: text/x-patch
Size: 1859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161219/f516596a/attachment.bin>


More information about the llvm-commits mailing list