Conversation
u8250_handle_out wrote to the buffer before checking bounds. If a prior flush failed (write error), out_buf_len stayed at 128 and the next call wrote past the end of out_buf, corrupting out_buf_len (adjacent struct field). Move the bounds check before the write so the invariant out_buf_len<128 holds at every array access. When flush cannot drain a full buffer, drop the byte rather than corrupt memory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
u8250_handle_out wrote to the buffer before checking bounds. If a prior flush failed (write error), out_buf_len stayed at 128 and the next call wrote past the end of out_buf, corrupting out_buf_len (adjacent struct field).
Move the bounds check before the write so the invariant out_buf_len<128 holds at every array access. When flush cannot drain a full buffer, drop the byte rather than corrupt memory.
Summary by cubic
Fixes a buffer overflow in the UART output path by checking buffer bounds before writing, flushing when full, and dropping the byte if the flush fails to prevent memory corruption. Also removes the redundant "flush when full" condition from the newline/marker path, since fullness is handled before the write.
Written for commit 07c058c. Summary will update on new commits.