Skip to content

Commit a3d0fb7

Browse files
committed
1. replacing magic number when fuzzing the number of transport types
2. using different parts of the fuzzed input data for TransportType and for Payload
1 parent b46ce9f commit a3d0fb7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

examples/all-clusters-app/linux/fuzzing-main.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize)
7474
// But maybe we should try to separately extract a PeerAddress and data from
7575
// the incoming data?
7676

77-
// dumping payload with random transport types
78-
Transport::Type fuzzedTransportType = static_cast<Transport::Type>(*aData % 5);
77+
// dumping payload with fuzzed transport types
78+
constexpr uint8_t numberOfTypes = static_cast<int>(Transport::Type::kLast) + 1;
79+
Transport::Type fuzzedTransportType = static_cast<Transport::Type>(aData[0] % numberOfTypes);
7980
Transport::PeerAddress peerAddr(fuzzedTransportType);
8081

82+
if (aSize < 1)
83+
{
84+
return 0;
85+
}
86+
8187
System::PacketBufferHandle buf =
82-
System::PacketBufferHandle::NewWithData(aData, aSize, /* aAdditionalSize = */ 0, /* aReservedSize = */ 0);
88+
System::PacketBufferHandle::NewWithData(&aData[1], aSize - 1, /* aAdditionalSize = */ 0, /* aReservedSize = */ 0);
8389
if (buf.IsNull())
8490
{
8591
// Too big; we couldn't represent this as a packetbuffer to start with.

0 commit comments

Comments
 (0)