diff options
author | Kostya Serebryany <kcc@google.com> | 2016-08-17 20:45:23 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-08-17 20:45:23 +0000 |
commit | a9a548049a29fb73b95bfdeea1a606b42a8d5c85 (patch) | |
tree | 3de0c00cd0f625a8e62ba87437339f7c2c217dfe | |
parent | 10ae33a9063d5f18a171d16f7f73ed97e42ee3a9 (diff) | |
download | bcm5719-llvm-a9a548049a29fb73b95bfdeea1a606b42a8d5c85.tar.gz bcm5719-llvm-a9a548049a29fb73b95bfdeea1a606b42a8d5c85.zip |
[libFuzzer] when printing the reproducer input, also print the base input and the mutation sequence
llvm-svn: 278975
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerInternal.h | 2 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerLoop.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerUtil.cpp | 12 |
3 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerInternal.h b/llvm/lib/Fuzzer/FuzzerInternal.h index 6ffaaf29236..861be803349 100644 --- a/llvm/lib/Fuzzer/FuzzerInternal.h +++ b/llvm/lib/Fuzzer/FuzzerInternal.h @@ -120,6 +120,7 @@ size_t GetPeakRSSMb(); static const int kSHA1NumBytes = 20; // Computes SHA1 hash of 'Len' bytes in 'Data', writes kSHA1NumBytes to 'Out'. void ComputeSHA1(const uint8_t *Data, size_t Len, uint8_t *Out); +std::string Sha1ToString(uint8_t Sha1[kSHA1NumBytes]); // Changes U to contain only ASCII (isprint+isspace) characters. // Returns true iff U has been changed. @@ -482,6 +483,7 @@ private: void LazyAllocateCurrentUnitData(); uint8_t *CurrentUnitData = nullptr; std::atomic<size_t> CurrentUnitSize; + uint8_t BaseSha1[kSHA1NumBytes]; // Checksum of the base unit. size_t TotalNumberOfRuns = 0; size_t NumberOfNewUnitsAdded = 0; diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp index 07de3c7c8b9..5d94483b8f9 100644 --- a/llvm/lib/Fuzzer/FuzzerLoop.cpp +++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp @@ -204,6 +204,8 @@ void Fuzzer::StaticDeathCallback() { void Fuzzer::DumpCurrentUnit(const char *Prefix) { if (!CurrentUnitData) return; // Happens when running individual inputs. + MD.PrintMutationSequence(); + Printf("; base unit: %s\n", Sha1ToString(BaseSha1).c_str()); size_t UnitSize = CurrentUnitSize; if (UnitSize <= kMaxUnitSizeToPrint) { PrintHexArray(CurrentUnitData, UnitSize, "\n"); @@ -693,6 +695,7 @@ void Fuzzer::MutateAndTestOne() { MD.StartMutationSequence(); auto &U = ChooseUnitToMutate(); + ComputeSHA1(U.data(), U.size(), BaseSha1); // Remember where we started. assert(CurrentUnitData); size_t Size = U.size(); assert(Size <= Options.MaxLen && "Oversized Unit"); diff --git a/llvm/lib/Fuzzer/FuzzerUtil.cpp b/llvm/lib/Fuzzer/FuzzerUtil.cpp index a5218d422da..6764a46e7d6 100644 --- a/llvm/lib/Fuzzer/FuzzerUtil.cpp +++ b/llvm/lib/Fuzzer/FuzzerUtil.cpp @@ -63,15 +63,19 @@ void PrintASCII(const Unit &U, const char *PrintAfter) { PrintASCII(U.data(), U.size(), PrintAfter); } -std::string Hash(const Unit &U) { - uint8_t Hash[kSHA1NumBytes]; - ComputeSHA1(U.data(), U.size(), Hash); +std::string Sha1ToString(uint8_t Sha1[kSHA1NumBytes]) { std::stringstream SS; for (int i = 0; i < kSHA1NumBytes; i++) - SS << std::hex << std::setfill('0') << std::setw(2) << (unsigned)Hash[i]; + SS << std::hex << std::setfill('0') << std::setw(2) << (unsigned)Sha1[i]; return SS.str(); } +std::string Hash(const Unit &U) { + uint8_t Hash[kSHA1NumBytes]; + ComputeSHA1(U.data(), U.size(), Hash); + return Sha1ToString(Hash); +} + static void AlarmHandler(int, siginfo_t *, void *) { Fuzzer::StaticAlarmCallback(); } |