From bbb5f2fd357e74154c4a7c926bf69a521fed99cf Mon Sep 17 00:00:00 2001 From: Alami-Amine Date: Thu, 19 Sep 2024 13:02:01 +0200 Subject: [PATCH] avoiding out of bounds access --- examples/all-clusters-app/linux/fuzzing-main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/all-clusters-app/linux/fuzzing-main.cpp b/examples/all-clusters-app/linux/fuzzing-main.cpp index cfca923adcffe0..943aeb90ec38c8 100644 --- a/examples/all-clusters-app/linux/fuzzing-main.cpp +++ b/examples/all-clusters-app/linux/fuzzing-main.cpp @@ -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(Transport::Type::kLast) + 1; Transport::Type fuzzedTransportType = static_cast(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())