mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
[libFuzzer] simplify CTOR of MutationDispatcher
llvm-svn: 260800
This commit is contained in:
parent
cca951bf4c
commit
abf7df0972
@ -174,7 +174,7 @@ private:
|
|||||||
|
|
||||||
class MutationDispatcher {
|
class MutationDispatcher {
|
||||||
public:
|
public:
|
||||||
MutationDispatcher(Random &Rand);
|
MutationDispatcher(Random &Rand) : Rand(Rand) {}
|
||||||
~MutationDispatcher() {}
|
~MutationDispatcher() {}
|
||||||
/// Indicate that we are about to start a new sequence of mutations.
|
/// Indicate that we are about to start a new sequence of mutations.
|
||||||
void StartMutationSequence();
|
void StartMutationSequence();
|
||||||
@ -236,7 +236,6 @@ private:
|
|||||||
const char *Name;
|
const char *Name;
|
||||||
};
|
};
|
||||||
|
|
||||||
void Add(Mutator M) { Mutators.push_back(M); }
|
|
||||||
size_t AddWordFromDictionary(Dictionary &D, uint8_t *Data, size_t Size,
|
size_t AddWordFromDictionary(Dictionary &D, uint8_t *Data, size_t Size,
|
||||||
size_t MaxSize);
|
size_t MaxSize);
|
||||||
|
|
||||||
@ -249,10 +248,11 @@ private:
|
|||||||
// Persistent dictionary modified by the fuzzer, consists of
|
// Persistent dictionary modified by the fuzzer, consists of
|
||||||
// entries that led to successfull discoveries in the past mutations.
|
// entries that led to successfull discoveries in the past mutations.
|
||||||
Dictionary PersistentAutoDictionary;
|
Dictionary PersistentAutoDictionary;
|
||||||
std::vector<Mutator> Mutators;
|
|
||||||
std::vector<Mutator> CurrentMutatorSequence;
|
std::vector<Mutator> CurrentMutatorSequence;
|
||||||
std::vector<DictionaryEntry *> CurrentDictionaryEntrySequence;
|
std::vector<DictionaryEntry *> CurrentDictionaryEntrySequence;
|
||||||
const std::vector<Unit> *Corpus = nullptr;
|
const std::vector<Unit> *Corpus = nullptr;
|
||||||
|
|
||||||
|
static Mutator Mutators[];
|
||||||
};
|
};
|
||||||
|
|
||||||
class Fuzzer {
|
class Fuzzer {
|
||||||
|
@ -18,6 +18,22 @@ namespace fuzzer {
|
|||||||
|
|
||||||
const size_t Dictionary::kMaxDictSize;
|
const size_t Dictionary::kMaxDictSize;
|
||||||
|
|
||||||
|
MutationDispatcher::Mutator MutationDispatcher::Mutators[] = {
|
||||||
|
{&MutationDispatcher::Mutate_EraseByte, "EraseByte"},
|
||||||
|
{&MutationDispatcher::Mutate_InsertByte, "InsertByte"},
|
||||||
|
{&MutationDispatcher::Mutate_ChangeByte, "ChangeByte"},
|
||||||
|
{&MutationDispatcher::Mutate_ChangeBit, "ChangeBit"},
|
||||||
|
{&MutationDispatcher::Mutate_ShuffleBytes, "ShuffleBytes"},
|
||||||
|
{&MutationDispatcher::Mutate_ChangeASCIIInteger, "ChangeASCIIInt"},
|
||||||
|
{&MutationDispatcher::Mutate_CrossOver, "CrossOver"},
|
||||||
|
{&MutationDispatcher::Mutate_AddWordFromManualDictionary,
|
||||||
|
"AddFromManualDict"},
|
||||||
|
{&MutationDispatcher::Mutate_AddWordFromTemporaryAutoDictionary,
|
||||||
|
"AddFromTempAutoDict"},
|
||||||
|
{&MutationDispatcher::Mutate_AddWordFromPersistentAutoDictionary,
|
||||||
|
"AddFromPersAutoDict"},
|
||||||
|
};
|
||||||
|
|
||||||
size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize, unsigned int Seed) {
|
size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize, unsigned int Seed) {
|
||||||
Random R(Seed);
|
Random R(Seed);
|
||||||
MutationDispatcher MD(R);
|
MutationDispatcher MD(R);
|
||||||
@ -233,7 +249,8 @@ size_t MutationDispatcher::Mutate(uint8_t *Data, size_t Size, size_t MaxSize) {
|
|||||||
// in which case they will return 0.
|
// in which case they will return 0.
|
||||||
// Try several times before returning un-mutated data.
|
// Try several times before returning un-mutated data.
|
||||||
for (int Iter = 0; Iter < 10; Iter++) {
|
for (int Iter = 0; Iter < 10; Iter++) {
|
||||||
size_t MutatorIdx = Rand(Mutators.size());
|
size_t NumMutators = sizeof(Mutators) / sizeof(Mutators[0]);
|
||||||
|
size_t MutatorIdx = Rand(NumMutators);
|
||||||
auto M = Mutators[MutatorIdx];
|
auto M = Mutators[MutatorIdx];
|
||||||
size_t NewSize = (this->*(M.Fn))(Data, Size, MaxSize);
|
size_t NewSize = (this->*(M.Fn))(Data, Size, MaxSize);
|
||||||
if (NewSize) {
|
if (NewSize) {
|
||||||
@ -260,21 +277,4 @@ void MutationDispatcher::ClearAutoDictionary() {
|
|||||||
TempAutoDictionary.clear();
|
TempAutoDictionary.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
MutationDispatcher::MutationDispatcher(Random &Rand) : Rand(Rand) {
|
|
||||||
Add({&MutationDispatcher::Mutate_EraseByte, "EraseByte"});
|
|
||||||
Add({&MutationDispatcher::Mutate_InsertByte, "InsertByte"});
|
|
||||||
Add({&MutationDispatcher::Mutate_ChangeByte, "ChangeByte"});
|
|
||||||
Add({&MutationDispatcher::Mutate_ChangeBit, "ChangeBit"});
|
|
||||||
Add({&MutationDispatcher::Mutate_ShuffleBytes, "ShuffleBytes"});
|
|
||||||
Add({&MutationDispatcher::Mutate_ChangeASCIIInteger, "ChangeASCIIInt"});
|
|
||||||
Add({&MutationDispatcher::Mutate_CrossOver, "CrossOver"});
|
|
||||||
Add({&MutationDispatcher::Mutate_AddWordFromManualDictionary,
|
|
||||||
"AddFromManualDict"});
|
|
||||||
Add({&MutationDispatcher::Mutate_AddWordFromTemporaryAutoDictionary,
|
|
||||||
"AddFromTempAutoDict"});
|
|
||||||
Add({&MutationDispatcher::Mutate_AddWordFromPersistentAutoDictionary,
|
|
||||||
"AddFromPersAutoDict"});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace fuzzer
|
} // namespace fuzzer
|
||||||
|
Loading…
Reference in New Issue
Block a user