From 58e7da1c05f942d7a81d5979d76dee107d16c1f0 Mon Sep 17 00:00:00 2001 From: Amine Alami <43780877+Alami-Amine@users.noreply.github.com> Date: Mon, 30 Sep 2024 22:28:12 +0200 Subject: [PATCH] [pw_fuzzer] Fix build failure + add coverage to payload decoder fuzztest (#35828) * Fix error due to missing std namespace specifier * Adding More protocol types (including invalid types) to Fuzzed Payload Decoder --- src/lib/dnssd/minimal_mdns/tests/FuzzPacketParsingPW.cpp | 4 ++-- src/lib/format/tests/FuzzPayloadDecoderPW.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/dnssd/minimal_mdns/tests/FuzzPacketParsingPW.cpp b/src/lib/dnssd/minimal_mdns/tests/FuzzPacketParsingPW.cpp index 0ea5de55013994..f49265f598a949 100644 --- a/src/lib/dnssd/minimal_mdns/tests/FuzzPacketParsingPW.cpp +++ b/src/lib/dnssd/minimal_mdns/tests/FuzzPacketParsingPW.cpp @@ -96,7 +96,7 @@ void TxtResponderFuzz(const std::vector & aRecord) auto equal_sign_pos = aRecord.end(); // This test is only giving a set of values, it can be gives more - vector prefixedRecord{ static_cast(aRecord.size()) }; + std::vector prefixedRecord{ static_cast(aRecord.size()) }; prefixedRecord.insert(prefixedRecord.end(), aRecord.begin(), aRecord.end()); @@ -126,6 +126,6 @@ void TxtResponderFuzz(const std::vector & aRecord) } } -FUZZ_TEST(MinimalmDNS, TxtResponderFuzz).WithDomains(Arbitrary>().WithMaxSize(254)); +FUZZ_TEST(MinimalmDNS, TxtResponderFuzz).WithDomains(Arbitrary>().WithMaxSize(254)); } // namespace diff --git a/src/lib/format/tests/FuzzPayloadDecoderPW.cpp b/src/lib/format/tests/FuzzPayloadDecoderPW.cpp index 52b51b308d0c2a..51f925bf2fdf87 100644 --- a/src/lib/format/tests/FuzzPayloadDecoderPW.cpp +++ b/src/lib/format/tests/FuzzPayloadDecoderPW.cpp @@ -59,13 +59,17 @@ void RunDecodeFuzz(const std::vector & 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>(), AnyProtocolID(), Arbitrary());