Skip to content

Fix buffer overflow in UART output buffering#127

Merged
jserv merged 1 commit intomasterfrom
fix-uart
Apr 24, 2026
Merged

Fix buffer overflow in UART output buffering#127
jserv merged 1 commit intomasterfrom
fix-uart

Conversation

@jserv
Copy link
Copy Markdown
Collaborator

@jserv jserv commented Apr 24, 2026

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.

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.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@jserv jserv merged commit cf635b3 into master Apr 24, 2026
11 checks passed
@jserv jserv deleted the fix-uart branch April 24, 2026 09:47
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.

1 participant