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
diff --git a/src/system/SystemPacketBuffer.cpp b/src/system/SystemPacketBuffer.cpp
index 20bd935..79e1bd2 100644
--- a/src/system/SystemPacketBuffer.cpp
+++ b/src/system/SystemPacketBuffer.cpp
@@ -151,6 +151,8 @@
return;
}
+ SYSTEM_STATS_INCREMENT(chip::System::Stats::kSystemLayer_NumPacketBufs);
+
uint8_t * const newStart = newBuffer->ReserveStart();
newBuffer->next = nullptr;
newBuffer->payload = newStart + (payload - start);