Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce a maximum entry limit during append operations #36843

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 32 additions & 0 deletions src/app/tests/suites/TestUserLabelClusterConstraints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,35 @@ tests:
]
response:
error: CONSTRAINT_ERROR

- label: "Attempt to write a large label list"
command: "writeAttribute"
attribute: "LabelList"
arguments:
value: [
# Example repeated user labels to blow up the maximum allowed
{ Label: "roomName", Value: "master bedroom 1" },
{ Label: "orientation", Value: "east" },
{ Label: "floor", Value: "2" },
{ Label: "roomType", Value: "bedroom" },
{ Label: "someKey5", Value: "someVal5" },
{ Label: "someKey6", Value: "someVal6" },
{ Label: "someKey7", Value: "someVal7" },
{ Label: "someKey8", Value: "someVal8" },
{ Label: "someKey9", Value: "someVal9" },
{ Label: "someKey10", Value: "someVal10" },
{ Label: "someKey11", Value: "someVal11" },
{ Label: "someKey12", Value: "someVal12" },
{ Label: "someKey13", Value: "someVal13" },
{ Label: "someKey14", Value: "someVal14" },
{ Label: "someKey15", Value: "someVal15" },
{ Label: "someKey16", Value: "someVal16" },
{ Label: "someKey17", Value: "someVal17" },
{ Label: "someKey18", Value: "someVal18" },
{ Label: "someKey19", Value: "someVal19" },
{ Label: "someKey20", Value: "someVal20" },
]
response:
# When the cluster runs out of capacity to store these entries,
# we expect a FAILURE get returned.
error: FAILURE
11 changes: 8 additions & 3 deletions src/platform/DeviceInfoProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ 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
if (length >= kMaxUserLabelListLength)
{
return CHIP_ERROR_NO_MEMORY;
yufengwangca marked this conversation as resolved.
Show resolved Hide resolved
}
yufengwangca marked this conversation as resolved.
Show resolved Hide resolved

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

return CHIP_NO_ERROR;
Expand Down
Loading