[llvm] r257435 - [libFuzzer] when a new unit is discovered using a dictionary, print all used dictionary entries
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 11 18:36:59 PST 2016
Author: kcc
Date: Mon Jan 11 20:36:59 2016
New Revision: 257435
URL: http://llvm.org/viewvc/llvm-project?rev=257435&view=rev
Log:
[libFuzzer] when a new unit is discovered using a dictionary, print all used dictionary entries
Modified:
llvm/trunk/lib/Fuzzer/FuzzerInternal.h
llvm/trunk/lib/Fuzzer/FuzzerMutate.cpp
llvm/trunk/lib/Fuzzer/FuzzerTraceState.cpp
llvm/trunk/lib/Fuzzer/FuzzerUtil.cpp
Modified: llvm/trunk/lib/Fuzzer/FuzzerInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerInternal.h?rev=257435&r1=257434&r2=257435&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerInternal.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerInternal.h Mon Jan 11 20:36:59 2016
@@ -38,6 +38,7 @@ std::string DirPlusFile(const std::strin
void Printf(const char *Fmt, ...);
void Print(const Unit &U, const char *PrintAfter = "");
+void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter = "");
void PrintASCII(const Unit &U, const char *PrintAfter = "");
std::string Hash(const Unit &U);
void SetTimer(int Seconds);
Modified: llvm/trunk/lib/Fuzzer/FuzzerMutate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerMutate.cpp?rev=257435&r1=257434&r2=257435&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerMutate.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerMutate.cpp Mon Jan 11 20:36:59 2016
@@ -32,6 +32,7 @@ struct MutationDispatcher::Impl {
std::vector<DictionaryEntry> AutoDictionary;
std::vector<Mutator> Mutators;
std::vector<Mutator> CurrentMutatorSequence;
+ std::vector<DictionaryEntry> CurrentDictionaryEntrySequence;
const std::vector<Unit> *Corpus = nullptr;
FuzzerRandomBase &Rand;
@@ -146,13 +147,14 @@ size_t MutationDispatcher::Impl::AddWord
size_t Idx = UsePositionHint ? PositionHint : Rand(Size + 1);
memmove(Data + Idx + Word.size(), Data + Idx, Size - Idx);
memcpy(Data + Idx, Word.data(), Word.size());
- return Size + Word.size();
+ Size += Word.size();
} else { // Overwrite some bytes with Word.
if (Word.size() > Size) return 0;
size_t Idx = UsePositionHint ? PositionHint : Rand(Size - Word.size());
memcpy(Data + Idx, Word.data(), Word.size());
- return Size;
}
+ CurrentDictionaryEntrySequence.push_back(DE);
+ return Size;
}
size_t MutationDispatcher::Mutate_ChangeASCIIInteger(uint8_t *Data, size_t Size,
@@ -206,12 +208,20 @@ size_t MutationDispatcher::Mutate_CrossO
void MutationDispatcher::StartMutationSequence() {
MDImpl->CurrentMutatorSequence.clear();
+ MDImpl->CurrentDictionaryEntrySequence.clear();
}
void MutationDispatcher::PrintMutationSequence() {
Printf("MS: %zd ", MDImpl->CurrentMutatorSequence.size());
for (auto M : MDImpl->CurrentMutatorSequence)
Printf("%s-", M.Name);
+ if (!MDImpl->CurrentDictionaryEntrySequence.empty()) {
+ Printf(" DE: ");
+ for (auto DE : MDImpl->CurrentDictionaryEntrySequence) {
+ Printf("\"");
+ PrintASCII(DE.Word, "\"-");
+ }
+ }
}
// Mutates Data in place, returns new size.
Modified: llvm/trunk/lib/Fuzzer/FuzzerTraceState.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTraceState.cpp?rev=257435&r1=257434&r2=257435&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTraceState.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTraceState.cpp Mon Jan 11 20:36:59 2016
@@ -170,25 +170,6 @@ struct TraceBasedMutation {
uint8_t Data[kMaxSize];
};
-static void PrintDataByte(uint8_t Byte) {
- if (Byte == '\\')
- Printf("\\\\");
- else if (Byte == '"')
- Printf("\\\"");
- else if (Byte >= 32 && Byte < 127)
- Printf("%c", Byte);
- else
- Printf("\\x%02x", Byte);
-}
-
-static void PrintData(const uint8_t *Data, size_t Size) {
- Printf("\"");
- for (size_t i = 0; i < Size; i++) {
- PrintDataByte(Data[i]);
- }
- Printf("\"");
-}
-
const size_t TraceBasedMutation::kMaxSize;
class TraceState {
@@ -249,7 +230,7 @@ class TraceState {
Printf("AutoDict:\n");
for (auto &I : CountedUnits) {
Printf(" %zd ", I.first);
- PrintData(I.second.data(), I.second.size());
+ PrintASCII(I.second);
Printf("\n");
}
}
@@ -440,8 +421,8 @@ void TraceState::TraceMemcmpCallback(siz
int Added1 = TryToAddDesiredData(Data2, Data1, CmpSize);
if ((Added1 || Added2) && Options.Verbosity >= 3) {
Printf("MemCmp Added %d%d: ", Added1, Added2);
- if (Added1) PrintData(Data1, CmpSize);
- if (Added2) PrintData(Data2, CmpSize);
+ if (Added1) PrintASCII(Data1, CmpSize);
+ if (Added2) PrintASCII(Data2, CmpSize);
Printf("\n");
}
}
Modified: llvm/trunk/lib/Fuzzer/FuzzerUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerUtil.cpp?rev=257435&r1=257434&r2=257435&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerUtil.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerUtil.cpp Mon Jan 11 20:36:59 2016
@@ -27,13 +27,26 @@ void Print(const Unit &v, const char *Pr
Printf("%s", PrintAfter);
}
+void PrintASCIIByte(uint8_t Byte) {
+ if (Byte == '\\')
+ Printf("\\\\");
+ else if (Byte == '"')
+ Printf("\\\"");
+ else if (Byte >= 32 && Byte < 127)
+ Printf("%c", Byte);
+ else
+ Printf("\\x%02x", Byte);
+}
+
+void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter) {
+ for (size_t i = 0; i < Size; i++)
+ PrintASCIIByte(Data[i]);
+ Printf("%s", PrintAfter);
+}
+
void PrintASCII(const Unit &U, const char *PrintAfter) {
- for (auto X : U) {
- if (isprint(X))
- Printf("%c", X);
- else
- Printf("\\x%x", (unsigned)X);
- }
+ for (auto X : U)
+ PrintASCIIByte(X);
Printf("%s", PrintAfter);
}
More information about the llvm-commits
mailing list