diff options
author | Kostya Serebryany <kcc@google.com> | 2015-07-24 01:06:40 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2015-07-24 01:06:40 +0000 |
commit | 404c69f2c8c7f7d4993f80fb1f7390571ffe56b6 (patch) | |
tree | 6396616273d6126f80ca341473538f9720740094 /llvm/lib/Fuzzer/FuzzerInterface.cpp | |
parent | 636cd262d6ae996e76faba51e24eccb603e7e42f (diff) | |
download | bcm5719-llvm-404c69f2c8c7f7d4993f80fb1f7390571ffe56b6.tar.gz bcm5719-llvm-404c69f2c8c7f7d4993f80fb1f7390571ffe56b6.zip |
[libFuzzer] allow users to supply their own implementation of rand
llvm-svn: 243078
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerInterface.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerInterface.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerInterface.cpp b/llvm/lib/Fuzzer/FuzzerInterface.cpp index dcd4e746013..c7553f421fb 100644 --- a/llvm/lib/Fuzzer/FuzzerInterface.cpp +++ b/llvm/lib/Fuzzer/FuzzerInterface.cpp @@ -14,14 +14,30 @@ #include "FuzzerInternal.h" namespace fuzzer { + +void FuzzerRandomLibc::ResetSeed(int seed) { srand(seed); } + +size_t FuzzerRandomLibc::Rand() { return rand(); } + +UserSuppliedFuzzer::UserSuppliedFuzzer() + : OwnRand(true), Rand(new FuzzerRandomLibc(0)) {} + +UserSuppliedFuzzer::UserSuppliedFuzzer(FuzzerRandomBase *Rand) : Rand(Rand) {} + +UserSuppliedFuzzer::~UserSuppliedFuzzer() { + if (OwnRand) + delete Rand; +} + size_t UserSuppliedFuzzer::BasicMutate(uint8_t *Data, size_t Size, size_t MaxSize) { - return ::fuzzer::Mutate(Data, Size, MaxSize); + return ::fuzzer::Mutate(Data, Size, MaxSize, *Rand); } size_t UserSuppliedFuzzer::BasicCrossOver(const uint8_t *Data1, size_t Size1, const uint8_t *Data2, size_t Size2, uint8_t *Out, size_t MaxOutSize) { - return ::fuzzer::CrossOver(Data1, Size1, Data2, Size2, Out, MaxOutSize); + return ::fuzzer::CrossOver(Data1, Size1, Data2, Size2, Out, MaxOutSize, + *Rand); } } // namespace fuzzer. |