diff --git a/src/app/clusters/user-label-server/user-label-server.cpp b/src/app/clusters/user-label-server/user-label-server.cpp index e1ea85cf01a78a..0030f628097696 100644 --- a/src/app/clusters/user-label-server/user-label-server.cpp +++ b/src/app/clusters/user-label-server/user-label-server.cpp @@ -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; diff --git a/src/app/tests/suites/TestUserLabelClusterConstraints.yaml b/src/app/tests/suites/TestUserLabelClusterConstraints.yaml index 4074def78d82d1..935fe88c2b662c 100644 --- a/src/app/tests/suites/TestUserLabelClusterConstraints.yaml +++ b/src/app/tests/suites/TestUserLabelClusterConstraints.yaml @@ -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 diff --git a/src/platform/DeviceInfoProvider.cpp b/src/platform/DeviceInfoProvider.cpp index 92ad84d86d49b8..28191cd4f82352 100644 --- a/src/platform/DeviceInfoProvider.cpp +++ b/src/platform/DeviceInfoProvider.cpp @@ -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; + } + + // Add the new entry to the list + ReturnErrorOnFailure(SetUserLabelLength(endpoint, length + 1)); ReturnErrorOnFailure(SetUserLabelAt(endpoint, length, label)); return CHIP_NO_ERROR;