Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyValueStoreManagerImpl::_Get does not seem to handle a large offset_bytes safely. #9479

Closed
bzbarsky-apple opened this issue Sep 4, 2021 · 2 comments
Labels
storage Involves NVM storage retreival/access V1.0

Comments

@bzbarsky-apple
Copy link
Contributor

Problem

The code looks like this:

    uint8_t buf[read_size];
    ReturnErrorOnFailure(mStorage.ReadValueBin(key, buf, read_size, read_size));

    size_t copy_size = std::min(value_size, read_size - offset_bytes);
...
    ::memcpy(value, buf + offset_bytes, copy_size);

What happens when offset_bytes > read_size? Looks to me like we will happily start reading at past the end of the buffer and probably read value_size bytes from there.

Proposed Solution

Probably need to return an error if offset_bytes > read_size.

@rgoliver @andy31415

tlykkeberg-grundfos added a commit to Grundfos/connectedhomeip that referenced this issue Sep 23, 2021
@andy31415 andy31415 added v1_triage_split_6 storage Involves NVM storage retreival/access and removed v1_triage_split_6 labels Jan 30, 2022
@andy31415
Copy link
Contributor

looks critical: memory safety issue (also fix seems easy enough if we just make it error out)

@andy31415
Copy link
Contributor

Marking fixed from #9954

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
storage Involves NVM storage retreival/access V1.0
Projects
None yet
Development

No branches or pull requests

3 participants