From 083a5a7b78209aabf6365003e4cfd463b6b00c0f Mon Sep 17 00:00:00 2001 From: Amine Alami <43780877+Alami-Amine@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:09:55 +0200 Subject: [PATCH] Bugfix: packet buffer counter going negative and triggering UBSan Issue (#35708) * Fix for issue where the packet buffer counter (sResourcesInUse[kSystemLayer_NumPacketBufs]) in SystemStats is going negative and underflowing, triggering a UBSan issue during fuzzing * Integrating comments --- src/system/SystemPacketBuffer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/system/SystemPacketBuffer.cpp b/src/system/SystemPacketBuffer.cpp index 20bd93540afe62..79e1bd25a67d8a 100644 --- a/src/system/SystemPacketBuffer.cpp +++ b/src/system/SystemPacketBuffer.cpp @@ -151,6 +151,8 @@ void PacketBufferHandle::InternalRightSize() return; } + SYSTEM_STATS_INCREMENT(chip::System::Stats::kSystemLayer_NumPacketBufs); + uint8_t * const newStart = newBuffer->ReserveStart(); newBuffer->next = nullptr; newBuffer->payload = newStart + (payload - start);