-
Notifications
You must be signed in to change notification settings - Fork 8k
shell: utils: Fix buffer overrun in shell_spaces_trim #23304
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
Conversation
The third argument in memmove can possible be greater than remaining buffer size. Just ensuring that memmove will changes bytes only inside the string buffer and nothing else. Signed-off-by: Flavio Ceolin <[email protected]>
May you please elaborate on how this can happen? Any example? |
I'll wait for a review from a shell subsystem maintainer before merging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned before. Please let me know what is the scenario to overrun the buffer?
Consider a long string which ends with two spaces followed by a non-space character. When the function calls memmove, the first and second arguments would point near the end of the string, while shift would be equal to 2. The third argument then ends up equal to the length of the string minus 3, which when added to either pointer results in a address that is located outside of the string buffer. |
@ceolin didn't want to push directly to your branch but i wrote the test to confirm the bug. Feel free to cherry-pick it into that PR: nordic-krch@abe8b15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ceolin thank you :)
The third argument in memmove can possible be greater than remaining
buffer size. Just ensuring that memmove will changes bytes only inside
the string buffer and nothing else.
Signed-off-by: Flavio Ceolin [email protected]