diff options
author | Tim Taubert <ttaubert@mozilla.com> | 2017-01-11 10:42:45 +0100 |
---|---|---|
committer | Tim Taubert <ttaubert@mozilla.com> | 2017-01-11 10:42:45 +0100 |
commit | 0109d22161c0a4199255324523c624d21818d3a1 (patch) | |
tree | 0a59c344bb49b61d065d6587e1b16fe21b19dccf /fuzz/shared.h | |
parent | 01b41f7f968bd6149274e5615d26dfd430d4f365 (diff) | |
download | nss-hg-0109d22161c0a4199255324523c624d21818d3a1.tar.gz |
Bug 1330237 - Call default mutators instead of patching libFuzzer r=mt
Differential Revision: https://nss-review.dev.mozaws.net/D141
Diffstat (limited to 'fuzz/shared.h')
-rw-r--r-- | fuzz/shared.h | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/fuzz/shared.h b/fuzz/shared.h index 107024904..3aac0d118 100644 --- a/fuzz/shared.h +++ b/fuzz/shared.h @@ -27,13 +27,23 @@ void QuickDERDecode(void *dst, const SEC_ASN1Template *tpl, const uint8_t *buf, PORT_DestroyCheapArena(&pool); } -#define ADD_CUSTOM_MUTATORS(...) \ - extern "C" size_t LLVMFuzzerCustomMutator( \ - uint8_t *Data, size_t Size, size_t MaxSize, unsigned int Seed) { \ - std::vector<decltype(LLVMFuzzerCustomMutator) *> mutators = __VA_ARGS__; \ - fuzzer::Random R(Seed); \ - auto idx = R(mutators.size()); \ - return mutators.at(idx)(Data, Size, MaxSize, Seed); \ +size_t CustomMutate(std::vector<decltype(LLVMFuzzerCustomMutator) *> mutators, + uint8_t *Data, size_t Size, size_t MaxSize, + unsigned int Seed) { + fuzzer::Random R(Seed); + + if (R.RandBool()) { + auto idx = R(mutators.size()); + return mutators.at(idx)(Data, Size, MaxSize, Seed); + } + + return LLVMFuzzerMutate(Data, Size, MaxSize); +} + +#define ADD_CUSTOM_MUTATORS(...) \ + extern "C" size_t LLVMFuzzerCustomMutator( \ + uint8_t *Data, size_t Size, size_t MaxSize, unsigned int Seed) { \ + return CustomMutate(__VA_ARGS__, Data, Size, MaxSize, Seed); \ } #endif // shared_h__ |