Skip to content

Commit 6018069

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Fix reservation logic in reporting engine. (#28542)
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.
1 parent 30050dc commit 6018069

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/app/reporting/Engine.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ CHIP_ERROR Engine::BuildSingleReportDataAttributeReportIBs(ReportDataMessage::Bu
9898
bool hasMoreChunks = true;
9999
TLV::TLVWriter backup;
100100
const uint32_t kReservedSizeEndOfReportIBs = 1;
101+
bool reservedEndOfReportIBs = false;
101102

102103
aReportDataBuilder.Checkpoint(backup);
103104

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

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

0 commit comments

Comments
 (0)