[llvm] r243795 - [libFuzzer] limit the size of the inputs printed to stderr

Kostya Serebryany kcc at google.com
Fri Jul 31 15:07:17 PDT 2015


Author: kcc
Date: Fri Jul 31 17:07:17 2015
New Revision: 243795

URL: http://llvm.org/viewvc/llvm-project?rev=243795&view=rev
Log:
[libFuzzer] limit the size of the inputs printed to stderr

Modified:
    llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp

Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=243795&r1=243794&r2=243795&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Fri Jul 31 17:07:17 2015
@@ -14,6 +14,7 @@
 #include <algorithm>
 
 namespace fuzzer {
+static const size_t kMaxUnitSizeToPrint = 4096;
 
 // Only one Fuzzer per process.
 static Fuzzer *F;
@@ -68,7 +69,8 @@ void Fuzzer::AlarmCallback() {
     Printf("ALARM: working on the last Unit for %zd seconds\n", Seconds);
     Printf("       and the timeout value is %d (use -timeout=N to change)\n",
            Options.UnitTimeoutSec);
-    Print(CurrentUnit, "\n");
+    if (CurrentUnit.size() <= kMaxUnitSizeToPrint)
+      Print(CurrentUnit, "\n");
     PrintUnitInASCIIOrTokens(CurrentUnit, "\n");
     WriteUnitToFileWithPrefix(CurrentUnit, "timeout-");
     exit(1);
@@ -160,7 +162,8 @@ size_t Fuzzer::RunOne(const Unit &U) {
   if (TimeOfUnit > TimeOfLongestUnitInSeconds) {
     TimeOfLongestUnitInSeconds = TimeOfUnit;
     Printf("Longest unit: %zd s:\n", TimeOfLongestUnitInSeconds);
-    Print(U, "\n");
+    if (U.size() <= kMaxUnitSizeToPrint)
+      Print(U, "\n");
     WriteUnitToFileWithPrefix(U, "long-running-unit-");
   }
   return Res;
@@ -252,8 +255,11 @@ void Fuzzer::WriteToOutputCorpus(const U
 void Fuzzer::WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix) {
   std::string Path = Prefix + Hash(U);
   WriteToFile(U, Path);
-  Printf("Test unit written to %s\nBase64: ", Path.c_str());
-  PrintFileAsBase64(Path);
+  Printf("Test unit written to %s\n", Path.c_str());
+  if (U.size() <= kMaxUnitSizeToPrint) {
+    Printf("Base64: ");
+    PrintFileAsBase64(Path);
+  }
 }
 
 void Fuzzer::SaveCorpus() {





More information about the llvm-commits mailing list