Google's FuzzTest
Finding Undefined Behavior with Sanitizers:
Find Correctness Bugs using Assertions:
Keywords: Property Function, Input Domain
FUZZ_TEST
:FUZZ_TEST(TLVReader, FuzzTlvReader).WithDomains(fuzztest::Arbitrary<std::vector<std::uint8_t>>());
The Macro invocation calls the Property Function, which is FuzzTlvReader
above.
The input domains define the range and type of inputs that the property function will receive during fuzzing, specified using the .WithDomains()
clause.
In the macro above, FuzzTest will generate a wide range of possible byte vectors to thoroughly test the FuzzTlvReader
function.
// The Property Function void FuzzTlvRead(const std::vector<std::uint8_t> & bytes) { TLVReader reader; reader.Init(bytes.data(), bytes.size()); chip::TLV::Utilities::Iterate(reader, FuzzIterator, nullptr); }
The Property Functions must return a void
The function will be run with many different inputs in the same process, trying to trigger a crash.
It is possible to include Assertions such as during Round-Trip Fuzzing
More Information: https://github.com/google/fuzztest/blob/main/doc/fuzz-test-macro.md#the-property-function
fuzztest::
namespace.Arbitrary<T>()
:FUZZ_TEST(Base38Decoder, FuzzQRCodeSetupPayloadParser).WithDomains(Arbitrary<std::string>());
.WithMaxSize()
or .WithMinSize()
, as shown below:FUZZ_TEST(MinimalmDNS, TxtResponderFuzz).WithDomains(Arbitrary<vector<uint8_t>>().WithMaxSize(254));
ElementOf
is particularly useful as it allows us to define a domain by explicitly enumerating the set of values in it and passing it to FuzzTest invocation. Example:auto AnyProtocolID() { return ElementOf({ chip::Protocols::SecureChannel::Id, chip::Protocols::InteractionModel::Id, chip::Protocols::BDX::Id, chip::Protocols::UserDirectedCommissioning::Id }); } FUZZ_TEST(PayloadDecoder, RunDecodeFuzz).WithDomains(Arbitrary<std::vector<std::uint8_t>>(), AnyProtocolID(), Arbitrary<uint8_t>());
There are several ways to run the tests:
./fuzz-chip-cert-pw
$ ./fuzz-chip-cert-pw --list_fuzz_tests [.] Sanitizer coverage enabled. Counter map size: 11134, Cmp map size: 262144 [*] Fuzz test: ChipCert.ChipCertFuzzer [*] Fuzz test: ChipCert.DecodeChipCertFuzzer $ ./fuzz-chip-cert-pw --fuzz=ChipCert.DecodeChipCertFuzzer
#both Fuzz Tests will be run for 10 minutes each ./fuzz-chip-cert-pw --fuzz_for=10m
# FuzzTest related help ./fuzz-chip-cert-pw --helpfull # gtest related help ./fuzz-chip-cert-pw --help