Skip to content

Commit

Permalink
Linux KVS Get impl should return buffer too small if the buffer is to…
Browse files Browse the repository at this point in the history
…o small (#19914)

* Linux KVS Get impl should return buffer too small if the buffer it too small

* use helper variable

* Restyle
  • Loading branch information
tehampson authored and pull[bot] committed Aug 11, 2023
1 parent 1bcbb26 commit 3367137
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/platform/Linux/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3367137

Please sign in to comment.