Skip to content

Commit 621f8dd

Browse files
[CSA-CP] User label max entry limit (#336)
Co-authored-by: Yufeng Wang <yufengwang@google.com>
1 parent c26cd91 commit 621f8dd

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

src/app/clusters/user-label-server/user-label-server.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ CHIP_ERROR UserLabelAttrAccess::WriteLabelList(const ConcreteDataAttributePath &
143143

144144
return provider->SetUserLabelList(endpoint, labelList);
145145
}
146+
146147
if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem)
147148
{
148149
Structs::LabelStruct::DecodableType entry;

src/app/tests/suites/TestUserLabelClusterConstraints.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,35 @@ tests:
5555
]
5656
response:
5757
error: CONSTRAINT_ERROR
58+
59+
- label: "Attempt to write a large label list"
60+
command: "writeAttribute"
61+
attribute: "LabelList"
62+
arguments:
63+
value: [
64+
# Example repeated user labels to blow up the maximum allowed
65+
{ Label: "roomName", Value: "master bedroom 1" },
66+
{ Label: "orientation", Value: "east" },
67+
{ Label: "floor", Value: "2" },
68+
{ Label: "roomType", Value: "bedroom" },
69+
{ Label: "someKey5", Value: "someVal5" },
70+
{ Label: "someKey6", Value: "someVal6" },
71+
{ Label: "someKey7", Value: "someVal7" },
72+
{ Label: "someKey8", Value: "someVal8" },
73+
{ Label: "someKey9", Value: "someVal9" },
74+
{ Label: "someKey10", Value: "someVal10" },
75+
{ Label: "someKey11", Value: "someVal11" },
76+
{ Label: "someKey12", Value: "someVal12" },
77+
{ Label: "someKey13", Value: "someVal13" },
78+
{ Label: "someKey14", Value: "someVal14" },
79+
{ Label: "someKey15", Value: "someVal15" },
80+
{ Label: "someKey16", Value: "someVal16" },
81+
{ Label: "someKey17", Value: "someVal17" },
82+
{ Label: "someKey18", Value: "someVal18" },
83+
{ Label: "someKey19", Value: "someVal19" },
84+
{ Label: "someKey20", Value: "someVal20" },
85+
]
86+
response:
87+
# When the cluster runs out of capacity to store these entries,
88+
# we expect a FAILURE get returned.
89+
error: FAILURE

src/platform/DeviceInfoProvider.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@ CHIP_ERROR DeviceInfoProvider::AppendUserLabel(EndpointId endpoint, const UserLa
8282
{
8383
size_t length;
8484

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

89-
// Append the user label at the end of UserLabelList
88+
if (length >= kMaxUserLabelListLength)
89+
{
90+
return CHIP_ERROR_NO_MEMORY;
91+
}
92+
93+
// Add the new entry to the list
94+
ReturnErrorOnFailure(SetUserLabelLength(endpoint, length + 1));
9095
ReturnErrorOnFailure(SetUserLabelAt(endpoint, length, label));
9196

9297
return CHIP_NO_ERROR;

0 commit comments

Comments
 (0)