[llvm] r244250 - [libFuzzer] move the mutators to public interface so that custom mutators may reuse these functions directly
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 6 12:19:56 PDT 2015
Author: kcc
Date: Thu Aug 6 14:19:55 2015
New Revision: 244250
URL: http://llvm.org/viewvc/llvm-project?rev=244250&view=rev
Log:
[libFuzzer] move the mutators to public interface so that custom mutators may reuse these functions directly
Modified:
llvm/trunk/lib/Fuzzer/FuzzerInterface.cpp
llvm/trunk/lib/Fuzzer/FuzzerInterface.h
llvm/trunk/lib/Fuzzer/FuzzerInternal.h
llvm/trunk/lib/Fuzzer/test/UserSuppliedFuzzerTest.cpp
Modified: llvm/trunk/lib/Fuzzer/FuzzerInterface.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerInterface.cpp?rev=244250&r1=244249&r2=244250&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerInterface.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerInterface.cpp Thu Aug 6 14:19:55 2015
@@ -29,15 +29,4 @@ UserSuppliedFuzzer::~UserSuppliedFuzzer(
delete Rand;
}
-size_t UserSuppliedFuzzer::BasicMutate(uint8_t *Data, size_t Size,
- size_t 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,
- *Rand);
-}
-
} // namespace fuzzer.
Modified: llvm/trunk/lib/Fuzzer/FuzzerInterface.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerInterface.h?rev=244250&r1=244249&r2=244250&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerInterface.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerInterface.h Thu Aug 6 14:19:55 2015
@@ -62,6 +62,34 @@ class FuzzerRandomLibc : public FuzzerRa
size_t Rand() override;
};
+
+/// Mutates data by shuffling bytes.
+size_t Mutate_ShuffleBytes(uint8_t *Data, size_t Size, size_t MaxSize,
+ FuzzerRandomBase &Rand);
+/// Mutates data by erasing a byte.
+size_t Mutate_EraseByte(uint8_t *Data, size_t Size, size_t MaxSize,
+ FuzzerRandomBase &Rand);
+/// Mutates data by inserting a byte.
+size_t Mutate_InsertByte(uint8_t *Data, size_t Size, size_t MaxSize,
+ FuzzerRandomBase &Rand);
+/// Mutates data by chanding one byte.
+size_t Mutate_ChangeByte(uint8_t *Data, size_t Size, size_t MaxSize,
+ FuzzerRandomBase &Rand);
+/// Mutates data by chanding one bit.
+size_t Mutate_ChangeBit(uint8_t *Data, size_t Size, size_t MaxSize,
+ FuzzerRandomBase &Rand);
+
+/// Applies one of the above mutations.
+/// Returns the new size of data which could be up to MaxSize.
+size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize,
+ FuzzerRandomBase &Rand);
+
+/// Creates a cross-over of two pieces of Data, returns its size.
+size_t CrossOver(const uint8_t *Data1, size_t Size1, const uint8_t *Data2,
+ size_t Size2, uint8_t *Out, size_t MaxOutSize,
+ FuzzerRandomBase &Rand);
+
+
/** An abstract class that allows to use user-supplied mutators with libFuzzer.
Usage:
@@ -94,25 +122,20 @@ class UserSuppliedFuzzer {
/// Mutates 'Size' bytes of data in 'Data' inplace into up to 'MaxSize' bytes,
/// returns the new size of the data, which should be positive.
virtual size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize) {
- return BasicMutate(Data, Size, MaxSize);
+ return ::fuzzer::Mutate(Data, Size, MaxSize, GetRand());
}
/// Crosses 'Data1' and 'Data2', writes up to 'MaxOutSize' bytes into Out,
/// returns the number of bytes written, which should be positive.
virtual size_t CrossOver(const uint8_t *Data1, size_t Size1,
const uint8_t *Data2, size_t Size2,
uint8_t *Out, size_t MaxOutSize) {
- return BasicCrossOver(Data1, Size1, Data2, Size2, Out, MaxOutSize);
+ return ::fuzzer::CrossOver(Data1, Size1, Data2, Size2, Out, MaxOutSize,
+ GetRand());
}
virtual ~UserSuppliedFuzzer();
FuzzerRandomBase &GetRand() { return *Rand; }
- protected:
- /// These can be called internally by Mutate and CrossOver.
- size_t BasicMutate(uint8_t *Data, size_t Size, size_t MaxSize);
- size_t BasicCrossOver(const uint8_t *Data1, size_t Size1,
- const uint8_t *Data2, size_t Size2,
- uint8_t *Out, size_t MaxOutSize);
private:
bool OwnRand = false;
FuzzerRandomBase *Rand;
Modified: llvm/trunk/lib/Fuzzer/FuzzerInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerInternal.h?rev=244250&r1=244249&r2=244250&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerInternal.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerInternal.h Thu Aug 6 14:19:55 2015
@@ -33,23 +33,6 @@ void CopyFileToErr(const std::string &Pa
std::string DirPlusFile(const std::string &DirPath,
const std::string &FileName);
-size_t Mutate_ShuffleBytes(uint8_t *Data, size_t Size, size_t MaxSize,
- FuzzerRandomBase &Rand);
-size_t Mutate_EraseByte(uint8_t *Data, size_t Size, size_t MaxSize,
- FuzzerRandomBase &Rand);
-size_t Mutate_InsertByte(uint8_t *Data, size_t Size, size_t MaxSize,
- FuzzerRandomBase &Rand);
-size_t Mutate_ChangeByte(uint8_t *Data, size_t Size, size_t MaxSize,
- FuzzerRandomBase &Rand);
-size_t Mutate_ChangeBit(uint8_t *Data, size_t Size, size_t MaxSize,
- FuzzerRandomBase &Rand);
-size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize,
- FuzzerRandomBase &Rand);
-
-size_t CrossOver(const uint8_t *Data1, size_t Size1, const uint8_t *Data2,
- size_t Size2, uint8_t *Out, size_t MaxOutSize,
- FuzzerRandomBase &Rand);
-
void Printf(const char *Fmt, ...);
void Print(const Unit &U, const char *PrintAfter = "");
void PrintASCII(const Unit &U, const char *PrintAfter = "");
Modified: llvm/trunk/lib/Fuzzer/test/UserSuppliedFuzzerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/UserSuppliedFuzzerTest.cpp?rev=244250&r1=244249&r2=244250&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/UserSuppliedFuzzerTest.cpp (original)
+++ llvm/trunk/lib/Fuzzer/test/UserSuppliedFuzzerTest.cpp Thu Aug 6 14:19:55 2015
@@ -37,8 +37,8 @@ class MyFuzzer : public fuzzer::UserSupp
Size = sizeof(kMagic);
// "Fix" the data, then mutate.
memcpy(Data, &kMagic, std::min(MaxSize, sizeof(kMagic)));
- return BasicMutate(Data + sizeof(kMagic), Size - sizeof(kMagic),
- MaxSize - sizeof(kMagic));
+ return fuzzer::UserSuppliedFuzzer::Mutate(
+ Data + sizeof(kMagic), Size - sizeof(kMagic), MaxSize - sizeof(kMagic));
}
// No need to redefine CrossOver() here.
};
More information about the llvm-commits
mailing list