From 2606809eeafabf24d4290e363c99bef4365c2dce Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 26 Jan 2022 21:32:52 -0500 Subject: [PATCH] Fix fuzzing handling of too-large inputs. (#14353) If we can't put it in a PacketBuffer, we can't do anything with it. Fixes https://github.com/project-chip/connectedhomeip/issues/14348 --- examples/all-clusters-app/linux/fuzzing-main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/all-clusters-app/linux/fuzzing-main.cpp b/examples/all-clusters-app/linux/fuzzing-main.cpp index f7fef1bb214fb1..043a9cb529da5b 100644 --- a/examples/all-clusters-app/linux/fuzzing-main.cpp +++ b/examples/all-clusters-app/linux/fuzzing-main.cpp @@ -61,6 +61,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize) Transport::PeerAddress peerAddr; System::PacketBufferHandle buf = System::PacketBufferHandle::NewWithData(aData, aSize, /* aAdditionalSize = */ 0, /* aReservedSize = */ 0); + if (buf.IsNull()) + { + // Too big; we couldn't represent this as a packetbuffer to start with. + return 0; + } // Ignoring the return value from OnMessageReceived, because we might be // passing it all sorts of garbage that will cause it to fail.