From 1724940f9a3f11991022b57faa6064fbaf12c4f6 Mon Sep 17 00:00:00 2001 From: lpbeliveau-silabs Date: Fri, 24 Mar 2023 14:23:43 -0400 Subject: [PATCH] Added missing checks, removed redundant ones in scene default handlers --- src/app/clusters/scenes/SceneTableImpl.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/app/clusters/scenes/SceneTableImpl.h b/src/app/clusters/scenes/SceneTableImpl.h index 00247c179945a8..11d83b14a5239d 100644 --- a/src/app/clusters/scenes/SceneTableImpl.h +++ b/src/app/clusters/scenes/SceneTableImpl.h @@ -58,19 +58,20 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler uint8_t pairCount = 0; // Verify size of list - extensionFieldSet.attributeValueList.ComputeSize(&pairTotal); - VerifyOrReturnError(pairTotal <= kMaxAvPair, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorOnFailure(extensionFieldSet.attributeValueList.ComputeSize(&pairTotal)); + VerifyOrReturnError(pairTotal <= Span(mAVPairs).size(), + CHIP_ERROR_BUFFER_TOO_SMALL); auto pair_iterator = extensionFieldSet.attributeValueList.begin(); - while (pair_iterator.Next() && pairCount < kMaxAvPair) + while (pair_iterator.Next()) { aVPair = pair_iterator.GetValue(); mAVPairs[pairCount].attributeID = aVPair.attributeID; size_t valueBytesTotal = 0; uint8_t valueBytesCount = 0; - aVPair.attributeValue.ComputeSize(&valueBytesTotal); - VerifyOrReturnError(valueBytesTotal <= kMaxValueSize, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorOnFailure(aVPair.attributeValue.ComputeSize(&valueBytesTotal)); + VerifyOrReturnError(valueBytesTotal <= Span(mValueBuffer[0]).size(), CHIP_ERROR_BUFFER_TOO_SMALL); auto value_iterator = aVPair.attributeValue.begin(); while (value_iterator.Next()) @@ -126,8 +127,9 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler attributeValueList.Decode(reader); // Verify size of list - attributeValueList.ComputeSize(&pairTotal); - VerifyOrReturnError(pairTotal <= kMaxAvPair, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorOnFailure(attributeValueList.ComputeSize(&pairTotal)); + VerifyOrReturnError(pairTotal <= Span(mAVPairs).size(), + CHIP_ERROR_BUFFER_TOO_SMALL); auto pair_iterator = attributeValueList.begin(); while (pair_iterator.Next()) @@ -138,11 +140,11 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler uint8_t valueBytesCount = 0; // Verify size of attribute value - decodePair.attributeValue.ComputeSize(&valueBytesTotal); - VerifyOrReturnError(valueBytesTotal <= kMaxValueSize, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorOnFailure(decodePair.attributeValue.ComputeSize(&valueBytesTotal)); + VerifyOrReturnError(valueBytesTotal <= Span(mValueBuffer[0]).size(), CHIP_ERROR_BUFFER_TOO_SMALL); auto value_iterator = decodePair.attributeValue.begin(); - while (value_iterator.Next() && valueBytesCount < kMaxValueSize) + while (value_iterator.Next()) { mValueBuffer[pairCount][valueBytesCount] = value_iterator.GetValue(); valueBytesCount++;