8000 Enforce constraints for sizes of labelstruct label and value lengths by andy31415 · Pull Request #20431 · project-chip/connectedhomeip · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Enforce constraints for sizes of labelstruct label and value lengths #20431

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 8000 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

Merged
merged 4 commits into from
Jul 8, 2022
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
27 changes: 27 additions & 0 deletions src/app/clusters/user-label-server/user-label-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ class UserLabelAttrAccess : public AttributeAccessInterface
CHIP_ERROR WriteLabelList(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder);
};

/// Matches constraints on a LabelStruct.
bool IsValidLabelEntry(const Structs::LabelStruct::Type & entry)
{
constexpr size_t kMaxLabelSize = 16;
constexpr size_t kMaxValueSize = 16;

// NOTE: spec default for label and value is empty, so empty is accepted here
return (entry.label.size() <= kMaxLabelSize) && (entry.value.size() <= kMaxValueSize);
}

bool IsValidLabelEntryList(const LabelList::TypeInfo::DecodableType & list)
{
auto iter = list.begin();
while (iter.Next())
{
if (!IsValidLabelEntry(iter.GetValue()))
{
return false;
}
}
return true;
}

UserLabelAttrAccess gAttrAccess;

CHIP_ERROR UserLabelAttrAccess::ReadLabelList(EndpointId endpoint, AttributeValueEncoder & aEncoder)
Expand Down Expand Up @@ -106,6 +129,7 @@ CHIP_ERROR UserLabelAttrAccess::WriteLabelList(const ConcreteDataAttributePath &
LabelList::TypeInfo::DecodableType decodablelist;

ReturnErrorOnFailure(aDecoder.Decode(decodablelist));
ReturnErrorCodeIf(!IsValidLabelEntryList(decodablelist), CHIP_ERROR_INVALID_ARGUMENT);

auto iter = decodablelist.begin();
while (iter.Next())
Expand All @@ -120,7 +144,10 @@ CHIP_ERROR UserLabelAttrAccess::WriteLabelList(const ConcreteDataAttributePath &
if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem)
{
Structs::LabelStruct::DecodableType entry;

ReturnErrorOnFailure(aDecoder.Decode(entry));
ReturnErrorCodeIf(!IsValidLabelEntry(entry), CHIP_ERROR_INVALID_ARGUMENT);

return provider->AppendUserLabel(endpoint, entry);
}

Expand Down
57 changes: 57 additions & 0 deletions src/app/tests/suites/TestUserLabelClusterConstraints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: User Label Cluster Tests

config:
nodeId: 0x12344321
cluster: "User Label"
endpoint: 0

tests:
- label: "Wait for the commissioned device to be retrieved"
cluster: "DelayCommands"
command: "WaitForCommissionee"
arguments:
values:
- name: "nodeId"
value: nodeId

- label: "Attempt to write overly long item for label"
command: "writeAttribute"
attribute: "label list"
arguments:
value:
[
{
label: "this is longer than sixteen characters",
value: "bedroom 2",
},
]
response:
error: FAILURE

- label: "Attempt to write overly long item for value"
command: "writeAttribute"
attribute: "label list"
arguments:
value:
[
{
label: "test",
value: "this is longer than sixteen characters",
},
]
response:
error: FAILURE
1 change: 1 addition & 0 deletions src/app/tests/suites/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ function getTests() {
"TestSystemCommands",
"TestBinding",
"TestUserLabelCluster",
"TestUserLabelClusterConstraints",
"TestArmFailSafe",
"TestFanControl",
];
Expand Down
114 changes: 114 additions & 0 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
0