Skip to content

Commit fec7b49

Browse files
committed
avoiding out of bounds access
1 parent 8f17d3b commit fec7b49

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ 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+
// To avoid out-of-bounds access when acessing aData[1]
78+
if (aSize < 2)
79+
{
80+
return 0;
81+
}
82+
7783
// dumping payload with fuzzed transport types
7884
constexpr uint8_t numberOfTypes = static_cast<int>(Transport::Type::kLast) + 1;
7985
Transport::Type fuzzedTransportType = static_cast<Transport::Type>(aData[0] % numberOfTypes);
8086
Transport::PeerAddress peerAddr(fuzzedTransportType);
8187

82-
if (aSize < 1)
83-
{
84-
return 0;
85-
}
86-
8788
System::PacketBufferHandle buf =
8889
System::PacketBufferHandle::NewWithData(&aData[1], aSize - 1, /* aAdditionalSize = */ 0, /* aReservedSize = */ 0);
8990
if (buf.IsNull())

0 commit comments

Comments
 (0)