Skip to content

Commit

Permalink
esp32_diagnostic_trace: add extra tlv closing bytes check before copy…
Browse files Browse the repository at this point in the history
…ing diagnostic
  • Loading branch information
pimpalemahesh committed Dec 13, 2024
1 parent defb136 commit 08a4b12
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <lib/support/CHIPMem.h>
#include <tracing/esp32_diagnostic_trace/Diagnostics.h>

#define TLV_CLOSING_BYTES 4

namespace chip {
namespace Tracing {
namespace Diagnostics {
Expand Down Expand Up @@ -89,7 +91,8 @@ class CircularDiagnosticBuffer : public chip::TLV::TLVCircularBuffer, public Dia
reader.GetTag() == chip::TLV::ContextTag(DIAGNOSTICS_TAG::TRACE) ||
reader.GetTag() == chip::TLV::ContextTag(DIAGNOSTICS_TAG::COUNTER)))
{
if ((reader.GetLengthRead() - writer.GetLengthWritten()) < (writer.GetRemainingFreeLength()))
if ((reader.GetLengthRead() - writer.GetLengthWritten()) <
((writer.GetRemainingFreeLength() + TLV_CLOSING_BYTES)))
{
err = writer.CopyElement(reader);
if (err == CHIP_ERROR_BUFFER_TOO_SMALL)
Expand Down

0 comments on commit 08a4b12

Please sign in to comment.