Skip to content

Commit

Permalink
Enforce a maximum entry limit during append operations
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Dec 13, 2024
1 parent d6bb79c commit f227584
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app/clusters/user-label-server/user-label-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ CHIP_ERROR UserLabelAttrAccess::WriteLabelList(const ConcreteDataAttributePath &

return provider->SetUserLabelList(endpoint, labelList);
}

if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem)
{
Structs::LabelStruct::DecodableType entry;
Expand Down
12 changes: 9 additions & 3 deletions src/platform/DeviceInfoProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ CHIP_ERROR DeviceInfoProvider::AppendUserLabel(EndpointId endpoint, const UserLa
{
size_t length;

// Increase the size of UserLabelList by 1
// Fetch current list length
ReturnErrorOnFailure(GetUserLabelLength(endpoint, length));
ReturnErrorOnFailure(SetUserLabelLength(endpoint, length + 1));

// Append the user label at the end of UserLabelList
// Enforce maximum entry limit
if (length >= kMaxUserLabelListLength)
{
return CHIP_ERROR_NO_MEMORY; // Return an error if the limit is exceeded
}

// Add the new entry to the list
ReturnErrorOnFailure(SetUserLabelLength(endpoint, length + 1));
ReturnErrorOnFailure(SetUserLabelAt(endpoint, length, label));

return CHIP_NO_ERROR;
Expand Down

0 comments on commit f227584

Please sign in to comment.