Skip to content

Commit

Permalink
Added missing checks, removed redundant ones in scene default handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbeliveau-silabs authored and pull[bot] committed Oct 12, 2023
1 parent 81a52f8 commit 1724940
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/app/clusters/scenes/SceneTableImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<app::Clusters::Scenes::Structs::AttributeValuePair::Type>(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<uint8_t>(mValueBuffer[0]).size(), CHIP_ERROR_BUFFER_TOO_SMALL);

auto value_iterator = aVPair.attributeValue.begin();
while (value_iterator.Next())
Expand Down Expand Up @@ -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<app::Clusters::Scenes::Structs::AttributeValuePair::Type>(mAVPairs).size(),
CHIP_ERROR_BUFFER_TOO_SMALL);

auto pair_iterator = attributeValueList.begin();
while (pair_iterator.Next())
Expand All @@ -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<uint8_t>(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++;
Expand Down

0 comments on commit 1724940

Please sign in to comment.