[PATCH] D27286: [libFuzzer] Diff 10 - Improve fread error handling.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 30 15:31:45 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/D27286

Files:
  lib/Fuzzer/FuzzerUtil.cpp


Index: lib/Fuzzer/FuzzerUtil.cpp
===================================================================
--- lib/Fuzzer/FuzzerUtil.cpp
+++ lib/Fuzzer/FuzzerUtil.cpp
@@ -207,11 +207,22 @@
 
 bool ExecuteCommandAndReadOutput(const std::string &Command, std::string *Out) {
   FILE *Pipe = OpenProcessPipe(Command.c_str(), "r");
-  if (!Pipe) return false;
+  if (!Pipe) {
+    Printf("OpenProcessPipe failed with %d.\n", errno);
+    return false;
+  }
+
   char Buff[1024];
   size_t N;
-  while ((N = fread(Buff, 1, sizeof(Buff), Pipe)) > 0)
+  while ((N = fread(Buff, 1, sizeof(Buff), Pipe)) == sizeof(Buff))
     Out->append(Buff, N);
+  if (ferror(Pipe)) {
+    Printf("Failed to read opened process pipe.\n");
+    return false;
+  }
+  // Add last data read.
+  Out->append(Buff, N);
+
   return true;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27286.79828.patch
Type: text/x-patch
Size: 808 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161130/2e5419cc/attachment.bin>


More information about the llvm-commits mailing list