[lib/Fuzzer] on crash print the contents of the crashy input as base64
llvm-svn: 236548
diff --git a/llvm/lib/Fuzzer/FuzzerIO.cpp b/llvm/lib/Fuzzer/FuzzerIO.cpp
index ef23d42..81f37aa 100644
--- a/llvm/lib/Fuzzer/FuzzerIO.cpp
+++ b/llvm/lib/Fuzzer/FuzzerIO.cpp
@@ -60,4 +60,9 @@
return DirPath + "/" + FileName;
}
+void PrintFileAsBase64(const std::string &Path) {
+ std::string Cmd = "base64 -w 0 < " + Path + "; echo";
+ system(Cmd.c_str());
+}
+
} // namespace fuzzer
diff --git a/llvm/lib/Fuzzer/FuzzerInternal.h b/llvm/lib/Fuzzer/FuzzerInternal.h
index 7787109..8948e34 100644
--- a/llvm/lib/Fuzzer/FuzzerInternal.h
+++ b/llvm/lib/Fuzzer/FuzzerInternal.h
@@ -40,6 +40,7 @@
void PrintASCII(const Unit &U, const char *PrintAfter = "");
std::string Hash(const Unit &U);
void SetTimer(int Seconds);
+void PrintFileAsBase64(const std::string &Path);
class Fuzzer {
public:
diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp
index 9dfe30b..3a19b22 100644
--- a/llvm/lib/Fuzzer/FuzzerLoop.cpp
+++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp
@@ -246,6 +246,8 @@
std::string Path = Prefix + Hash(U);
WriteToFile(U, Path);
std::cerr << "CRASHED; file written to " << Path << std::endl;
+ std::cerr << "Base64: ";
+ PrintFileAsBase64(Path);
}
void Fuzzer::SaveCorpus() {