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 Aug 7, 2023
1 parent d4e1bca commit 35cb562
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 35cb562

Please sign in to comment.