Skip to content

Commit

Permalink
Fix reservation logic in reporting engine. (#28542)
Browse files Browse the repository at this point in the history
In BuildSingleReportDataAttributeReportIBs if we failed to successfully call
ReserveBuffer(kReservedSizeEndOfReportIBs) (because there was not enough space
in the packet), we would end up trying to EndOfAttributeReportIBs() after
unreserving (which would not match our never-happened reserve) and then
VerifyOrDie that we succeeded.

The fix is to keep track of whether we actually successfully reserved things,
and not override out-of-space-errors if we have not.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 17, 2023
1 parent dd5640b commit 1103600
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ CHIP_ERROR Engine::BuildSingleReportDataAttributeReportIBs(ReportDataMessage::Bu
bool hasMoreChunks = true;
TLV::TLVWriter backup;
const uint32_t kReservedSizeEndOfReportIBs = 1;
bool reservedEndOfReportIBs = false;

aReportDataBuilder.Checkpoint(backup);

Expand All @@ -110,7 +111,8 @@ CHIP_ERROR Engine::BuildSingleReportDataAttributeReportIBs(ReportDataMessage::Bu
//
// Reserve enough space for closing out the Report IB list
//
attributeReportIBs.GetWriter()->ReserveBuffer(kReservedSizeEndOfReportIBs);
SuccessOrExit(err = attributeReportIBs.GetWriter()->ReserveBuffer(kReservedSizeEndOfReportIBs));
reservedEndOfReportIBs = true;

{
// TODO: Figure out how AttributePathExpandIterator should handle read
Expand Down Expand Up @@ -251,7 +253,7 @@ CHIP_ERROR Engine::BuildSingleReportDataAttributeReportIBs(ReportDataMessage::Bu
// These are are guaranteed to not fail since we've already reserved memory for the remaining 'close out' TLV operations in this
// function and its callers.
//
if (IsOutOfWriterSpaceError(err))
if (IsOutOfWriterSpaceError(err) && reservedEndOfReportIBs)
{
ChipLogDetail(DataManagement, "<RE:Run> We cannot put more chunks into this report. Enable chunking.");
err = CHIP_NO_ERROR;
Expand Down

0 comments on commit 1103600

Please sign in to comment.