Skip to content

Commit

Permalink
Added ArraySize() for checks in default scne handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbeliveau-silabs authored and pull[bot] committed Nov 6, 2023
1 parent c56ea8a commit 1091224
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/app/clusters/scenes/SceneTableImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler

// Verify size of list
ReturnErrorOnFailure(extensionFieldSet.attributeValueList.ComputeSize(&pairTotal));
VerifyOrReturnError(pairTotal <= Span<app::Clusters::Scenes::Structs::AttributeValuePair::Type>(mAVPairs).size(),
CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(pairTotal <= ArraySize(mAVPairs), CHIP_ERROR_BUFFER_TOO_SMALL);

auto pair_iterator = extensionFieldSet.attributeValueList.begin();
while (pair_iterator.Next())
Expand All @@ -71,7 +70,7 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler
uint8_t valueBytesCount = 0;

ReturnErrorOnFailure(aVPair.attributeValue.ComputeSize(&valueBytesTotal));
VerifyOrReturnError(valueBytesTotal <= Span<uint8_t>(mValueBuffer[0]).size(), CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(valueBytesTotal <= ArraySize(mValueBuffer[0]), CHIP_ERROR_BUFFER_TOO_SMALL);

auto value_iterator = aVPair.attributeValue.begin();
while (value_iterator.Next())
Expand Down Expand Up @@ -128,8 +127,7 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler

// Verify size of list
ReturnErrorOnFailure(attributeValueList.ComputeSize(&pairTotal));
VerifyOrReturnError(pairTotal <= Span<app::Clusters::Scenes::Structs::AttributeValuePair::Type>(mAVPairs).size(),
CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(pairTotal <= ArraySize(mAVPairs), CHIP_ERROR_BUFFER_TOO_SMALL);

auto pair_iterator = attributeValueList.begin();
while (pair_iterator.Next())
Expand All @@ -141,7 +139,7 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler

// Verify size of attribute value
ReturnErrorOnFailure(decodePair.attributeValue.ComputeSize(&valueBytesTotal));
VerifyOrReturnError(valueBytesTotal <= Span<uint8_t>(mValueBuffer[0]).size(), CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(valueBytesTotal <= ArraySize(mValueBuffer[0]), CHIP_ERROR_BUFFER_TOO_SMALL);

auto value_iterator = decodePair.attributeValue.begin();
while (value_iterator.Next())
Expand Down

0 comments on commit 1091224

Please sign in to comment.