From 25476419218243d6a04dc0100181da37b2bf010f Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Sat, 13 May 2023 12:20:38 +0200 Subject: [PATCH] [Tizen] Account for 0-terminator in WriteConfigValueStr (#26510) * [Tizen] Account for 0-terminator in WriteConfigValueStr * Fix null-terminator implementation after review * Update src/platform/Tizen/PosixConfig.cpp --------- Co-authored-by: Boris Zbarsky --- src/platform/Tizen/PosixConfig.cpp | 11 ++++++++++- src/platform/tests/TestConfigurationMgr.cpp | 5 ++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/platform/Tizen/PosixConfig.cpp b/src/platform/Tizen/PosixConfig.cpp index fc65c24bf189a9..c8b2d36d8271bf 100644 --- a/src/platform/Tizen/PosixConfig.cpp +++ b/src/platform/Tizen/PosixConfig.cpp @@ -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) diff --git a/src/platform/tests/TestConfigurationMgr.cpp b/src/platform/tests/TestConfigurationMgr.cpp index dafe5b209725a2..a113594868ad2c 100644 --- a/src/platform/tests/TestConfigurationMgr.cpp +++ b/src/platform/tests/TestConfigurationMgr.cpp @@ -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), @@ -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.