Skip to content

Commit

Permalink
[KVS] Check NULL pointer for getPref_bin_new (#21854)
Browse files Browse the repository at this point in the history
* [KVS] Add NULL pointer check for getPref_bin_new

Invalid read_bytes_size pointer could cause hard fault on getPref_bin_new function.

* [KVS] Pass in dummy_read_bytes when read_bytes is nullptr

* [Restyle] Fix styling

* [KVS] Add nullptr check after pvPortMalloc

* [Restyle] Fix style

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
pankore and andy31415 authored Aug 23, 2022
1 parent 8702d3a commit 27ca045
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/platform/Ameba/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,20 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
return (err = CHIP_ERROR_NOT_IMPLEMENTED);
}

ret = getPref_bin_new(key, key, (uint8_t *) value, value_size, read_bytes_size);
if (read_bytes_size)
{
ret = getPref_bin_new(key, key, (uint8_t *) value, value_size, read_bytes_size);
}
else
{
size_t * dummy_read_bytes_size = (size_t *) pvPortMalloc(sizeof(size_t));
if (!dummy_read_bytes_size)
{
return CHIP_ERROR_INTERNAL;
}
ret = getPref_bin_new(key, key, (uint8_t *) value, value_size, dummy_read_bytes_size);
vPortFree(dummy_read_bytes_size);
}
switch (ret)
{
case 0:
Expand Down

0 comments on commit 27ca045

Please sign in to comment.