From 35852174d64040306a64efc2d76308053f1b06f9 Mon Sep 17 00:00:00 2001 From: tehampson Date: Thu, 23 Jun 2022 17:46:15 -0400 Subject: [PATCH] Linux KVS Get impl should return buffer too small if the buffer is too small (#19914) * Linux KVS Get impl should return buffer too small if the buffer it too small * use helper variable * Restyle --- src/platform/Linux/KeyValueStoreManagerImpl.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/platform/Linux/KeyValueStoreManagerImpl.cpp b/src/platform/Linux/KeyValueStoreManagerImpl.cpp index 6e1774759bcb42..2adc7b47ed9773 100644 --- a/src/platform/Linux/KeyValueStoreManagerImpl.cpp +++ b/src/platform/Linux/KeyValueStoreManagerImpl.cpp @@ -65,14 +65,15 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t VerifyOrReturnError(buf.Alloc(read_size), CHIP_ERROR_NO_MEMORY); ReturnErrorOnFailure(mStorage.ReadValueBin(key, buf.Get(), read_size, read_size)); - size_t copy_size = std::min(value_size, read_size - offset_bytes); + size_t total_size_to_read = read_size - offset_bytes; + size_t copy_size = std::min(value_size, total_size_to_read); if (read_bytes_size != nullptr) { *read_bytes_size = copy_size; } ::memcpy(value, buf.Get() + offset_bytes, copy_size); - return CHIP_NO_ERROR; + return (value_size < total_size_to_read) ? CHIP_ERROR_BUFFER_TOO_SMALL : CHIP_NO_ERROR; } CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size)