Skip to content

Commit

Permalink
[Tizen] Account for 0-terminator in WriteConfigValueStr (#26510)
Browse files Browse the repository at this point in the history
* [Tizen] Account for 0-terminator in WriteConfigValueStr

* Fix null-terminator implementation after review

* Update src/platform/Tizen/PosixConfig.cpp

---------

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
arkq and bzbarsky-apple authored May 13, 2023
1 parent 42f38de commit 4083b32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/platform/Tizen/PosixConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@ CHIP_ERROR PosixConfig::ReadConfigValue(Key key, uint64_t & val)
CHIP_ERROR PosixConfig::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen)
{
VerifyOrReturnError(buf != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
return PersistedStorage::KeyValueStoreMgr().Get(key.Name, buf, bufSize, &outLen);

auto err = PersistedStorage::KeyValueStoreMgr().Get(key.Name, buf, bufSize, &outLen);
VerifyOrReturnError(err == CHIP_NO_ERROR, err);

// We are storing string values in the config store without
// the null terminator, so we need to add it here.
VerifyOrReturnError(bufSize >= outLen + 1, CHIP_ERROR_BUFFER_TOO_SMALL);
buf[outLen] = '\0';

return CHIP_NO_ERROR;
}

CHIP_ERROR PosixConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen)
Expand Down
5 changes: 2 additions & 3 deletions src/platform/tests/TestConfigurationMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ static void TestConfigurationMgr_GetProductId(nlTestSuite * inSuite, void * inCo
* Test Suite. It lists all the test functions.
*/
static const nlTest sTests[] = {

NL_TEST_DEF("Test PlatformMgr::Init", TestPlatformMgr_Init),
#if !defined(NDEBUG)
NL_TEST_DEF("Test PlatformMgr::RunUnitTest", TestPlatformMgr_RunUnitTest),
Expand All @@ -466,8 +465,8 @@ static const nlTest sTests[] = {
NL_TEST_DEF("Test ConfigurationMgr::GetVendorId", TestConfigurationMgr_GetVendorId),
NL_TEST_DEF("Test ConfigurationMgr::GetProductName", TestConfigurationMgr_GetProductName),
NL_TEST_DEF("Test ConfigurationMgr::GetProductId", TestConfigurationMgr_GetProductId),
NL_TEST_SENTINEL()
}; // namespace
NL_TEST_SENTINEL(),
};

/**
* Set up the test suite.
Expand Down

0 comments on commit 4083b32

Please sign in to comment.