Skip to content

Commit

Permalink
[pw_fuzzer] Fix build failure + add coverage to payload decoder fuzzt…
Browse files Browse the repository at this point in the history
…est (project-chip#35828)

* Fix error due to missing std namespace specifier

* Adding More protocol types (including invalid types) to Fuzzed Payload Decoder
  • Loading branch information
Alami-Amine authored Sep 30, 2024
1 parent 9c6c365 commit 58e7da1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lib/dnssd/minimal_mdns/tests/FuzzPacketParsingPW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void TxtResponderFuzz(const std::vector<std::uint8_t> & aRecord)
auto equal_sign_pos = aRecord.end();

// This test is only giving a set of values, it can be gives more
vector<uint8_t> prefixedRecord{ static_cast<uint8_t>(aRecord.size()) };
std::vector<uint8_t> prefixedRecord{ static_cast<std::uint8_t>(aRecord.size()) };

prefixedRecord.insert(prefixedRecord.end(), aRecord.begin(), aRecord.end());

Expand Down Expand Up @@ -126,6 +126,6 @@ void TxtResponderFuzz(const std::vector<std::uint8_t> & aRecord)
}
}

FUZZ_TEST(MinimalmDNS, TxtResponderFuzz).WithDomains(Arbitrary<vector<uint8_t>>().WithMaxSize(254));
FUZZ_TEST(MinimalmDNS, TxtResponderFuzz).WithDomains(Arbitrary<std::vector<std::uint8_t>>().WithMaxSize(254));

} // namespace
8 changes: 6 additions & 2 deletions src/lib/format/tests/FuzzPayloadDecoderPW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ void RunDecodeFuzz(const std::vector<std::uint8_t> & bytes, chip::Protocols::Id
}
}

// This function allows us to fuzz using one of four protocols; by using FuzzTests's `ElementOf` API, we define an
// This function allows us to fuzz using all existing protocols; by using FuzzTests's `ElementOf` API, we define an
// input domain by explicitly enumerating the set of values in it More Info:
// https://github.com/google/fuzztest/blob/main/doc/domains-reference.md#elementof-domains-element-of
auto AnyProtocolID()
{
// Adding an Invalid Protocol
static constexpr chip::Protocols::Id InvalidProtocolID(chip::VendorId::Common, 2121);

return ElementOf({ chip::Protocols::SecureChannel::Id, chip::Protocols::InteractionModel::Id, chip::Protocols::BDX::Id,
chip::Protocols::UserDirectedCommissioning::Id });
chip::Protocols::UserDirectedCommissioning::Id, chip::Protocols::Echo::Id, chip::Protocols::NotSpecified,
InvalidProtocolID });
}

FUZZ_TEST(PayloadDecoder, RunDecodeFuzz).WithDomains(Arbitrary<std::vector<std::uint8_t>>(), AnyProtocolID(), Arbitrary<uint8_t>());
Expand Down

0 comments on commit 58e7da1

Please sign in to comment.