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 valid spec-conformant string encoding in TLV #30393

Merged
merged 16 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions src/app/clusters/scenes-server/SceneTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ class SceneTable
}
~SceneData(){};

bool operator==(const SceneData &other) const {
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
return (
(CharSpan(mName, mNameLength) == CharSpan(other.mName, other.mNameLength)) &&
(mSceneTransitionTimeMs == other.mSceneTransitionTimeMs) &&
(mExtensionFieldSets == other.mExtensionFieldSets)
);
}

void SetName(const CharSpan & sceneName)
{
if (nullptr == sceneName.data())
Expand All @@ -203,8 +211,7 @@ class SceneTable

void Clear()
{
SetName(CharSpan());

memset(mName, 0, sizeof(mName));
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
mSceneTransitionTimeMs = 0;
mExtensionFieldSets.Clear();
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/clusters/scenes-server/SceneTableImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ struct SceneTableData : public SceneTableEntry, PersistentData<kPersistentSceneB

CHIP_ERROR Serialize(TLV::TLVWriter & writer) const override
{
CharSpan nameSpan(mStorageData.mName, mStorageData.mNameLength);
// TODO: if we have mNameLength, should this bin ByteSpan instead?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment.

CharSpan nameSpan(mStorageData.mName, strnlen(mStorageData.mName, mStorageData.mNameLength));
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
TLV::TLVType container;
ReturnErrorOnFailure(writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, container));

Expand Down
2 changes: 1 addition & 1 deletion src/lib/support/tests/TestTlvJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void TestConverter(nlTestSuite * inSuite, void * inContext)
"}\n");

const char charBuf[] = "hello";
CharSpan charSpan(charBuf);
CharSpan charSpan = CharSpan::fromCharString(charBuf);
EncodeAndValidate(charSpan,
"{\n"
" \"value\" : \"hello\"\n"
Expand Down
Loading