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

[ESP32] Do not crash if storage delegate is nullptr #21822

Merged
Merged
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
9 changes: 6 additions & 3 deletions src/platform/ESP32/ESP32DeviceInfoProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,22 @@ bool ESP32DeviceInfoProvider::FixedLabelIteratorImpl::Next(FixedLabelType & outp

CHIP_ERROR ESP32DeviceInfoProvider::SetUserLabelLength(EndpointId endpoint, size_t val)
{
VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INCORRECT_STATE);
DefaultStorageKeyAllocator keyAlloc;
return mStorage->SyncSetKeyValue(keyAlloc.UserLabelLengthKey(endpoint), &val, static_cast<uint16_t>(sizeof(val)));
}

CHIP_ERROR ESP32DeviceInfoProvider::GetUserLabelLength(EndpointId endpoint, size_t & val)
{
VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INCORRECT_STATE);
DefaultStorageKeyAllocator keyAlloc;
uint16_t len = static_cast<uint16_t>(sizeof(val));
return mStorage->SyncGetKeyValue(keyAlloc.UserLabelLengthKey(endpoint), &val, len);
}

CHIP_ERROR ESP32DeviceInfoProvider::SetUserLabelAt(EndpointId endpoint, size_t index, const UserLabelType & userLabel)
{
VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INCORRECT_STATE);
DefaultStorageKeyAllocator keyAlloc;
uint8_t buf[UserLabelTLVMaxSize()];
TLV::TLVWriter writer;
Expand All @@ -125,6 +128,7 @@ CHIP_ERROR ESP32DeviceInfoProvider::SetUserLabelAt(EndpointId endpoint, size_t i

CHIP_ERROR ESP32DeviceInfoProvider::DeleteUserLabelAt(EndpointId endpoint, size_t index)
{
VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INCORRECT_STATE);
DefaultStorageKeyAllocator keyAlloc;
return mStorage->SyncDeleteKeyValue(keyAlloc.UserLabelIndexKey(endpoint, index));
}
Expand All @@ -146,15 +150,14 @@ ESP32DeviceInfoProvider::UserLabelIteratorImpl::UserLabelIteratorImpl(ESP32Devic

bool ESP32DeviceInfoProvider::UserLabelIteratorImpl::Next(UserLabelType & output)
{
CHIP_ERROR err = CHIP_NO_ERROR;

VerifyOrReturnError(mProvider.mStorage != nullptr, false);
VerifyOrReturnError(mIndex < mTotal, false);

DefaultStorageKeyAllocator keyAlloc;
uint8_t buf[UserLabelTLVMaxSize()];
uint16_t len = static_cast<uint16_t>(sizeof(buf));

err = mProvider.mStorage->SyncGetKeyValue(keyAlloc.UserLabelIndexKey(mEndpoint, mIndex), buf, len);
CHIP_ERROR err = mProvider.mStorage->SyncGetKeyValue(keyAlloc.UserLabelIndexKey(mEndpoint, mIndex), buf, len);
VerifyOrReturnError(err == CHIP_NO_ERROR, false);

TLV::ContiguousBufferTLVReader reader;
Expand Down