Skip to content

Commit

Permalink
avoiding out of bounds access
Browse files Browse the repository at this point in the history
  • Loading branch information
Alami-Amine committed Sep 19, 2024
1 parent 8f17d3b commit bbb5f2f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions examples/all-clusters-app/linux/fuzzing-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize)
// But maybe we should try to separately extract a PeerAddress and data from
// the incoming data?

//To avoid out-of-bounds access when acessing aData[1]
if (aSize < 2)
{
return 0;
}

// dumping payload with fuzzed transport types
constexpr uint8_t numberOfTypes = static_cast<int>(Transport::Type::kLast) + 1;
Transport::Type fuzzedTransportType = static_cast<Transport::Type>(aData[0] % numberOfTypes);
Transport::PeerAddress peerAddr(fuzzedTransportType);

if (aSize < 1)
{
return 0;
}

System::PacketBufferHandle buf =
System::PacketBufferHandle::NewWithData(&aData[1], aSize - 1, /* aAdditionalSize = */ 0, /* aReservedSize = */ 0);
if (buf.IsNull())
Expand Down

0 comments on commit bbb5f2f

Please sign in to comment.