mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-24 21:25:41 +00:00
[libFuzzer] when a new unit is discovered using a dictionary, print all used dictionary entries
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257435 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
71afbb96dc
commit
7b0624d17e
@ -38,6 +38,7 @@ std::string DirPlusFile(const std::string &DirPath,
|
||||
|
||||
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);
|
||||
|
@ -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::AddWordFromDictionary(
|
||||
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_CrossOver(uint8_t *Data, size_t Size,
|
||||
|
||||
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.
|
||||
|
@ -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(size_t CmpSize, const uint8_t *Data1,
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
@ -27,13 +27,26 @@ void Print(const Unit &v, const char *PrintAfter) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user