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

fix: prevent a potential buffer overflow #1

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

syncom
Copy link
Member

@syncom syncom commented Aug 23, 2024

When the total number of read octets is greater than the max return buffer size in bytes, we return a failure status (-1) instead of jumping out of the loop. Otherwise, a number larger than the maximum return buffer size might be returned upon success, which if unchecked by the caller, might cause a buffer overflow.

Note that the call to reader.read(&mut ret_buffer[total_bytes_read..]) might return a value less than or equal to the available space in ret_buffer, which would make total_bytes_read no larger than the max return buffer size. However, we'd like to make the code safer by not depending on an assumption on the implementation of the read method.

When the total number of read octets is greater than the max return
buffer size in bytes, we return a failure status (-1) instead of jumping
out of the loop. Otherwise, a number larger than the maximum return
buffer size might be returned upon success, which if unchecked by the
caller, might cause a buffer overflow.

Note that the call to `reader.read(&mut ret_buffer[total_bytes_read..])`
might return a value less than or equal to the available space in
ret_buffer, which would make total_bytes_read no larger than the max
return buffer size. However, we'd like not to make the code safer by not
depending on an assumption on the implementation of the `read` method.
@syncom syncom requested a review from pldubouilh August 23, 2024 00:27
Add a build check job in the sanity checks workflow.
@pldubouilh
Copy link
Collaborator

Sounds good - thanks for the PR 👍

@pldubouilh pldubouilh merged commit ad0d08c into main Aug 23, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants