Skip to content

fix(terminal): off-by-one in terminal_set_cursor bounds check - #107

Merged
im-nymii merged 1 commit into
Auri-OS:developfrom
kudasaixc:fix/terminal-set-cursor-bounds
Jul 24, 2026
Merged

fix(terminal): off-by-one in terminal_set_cursor bounds check#107
im-nymii merged 1 commit into
Auri-OS:developfrom
kudasaixc:fix/terminal-set-cursor-bounds

Conversation

@kudasaixc

Copy link
Copy Markdown
Contributor

x == VGA_WIDTH and y == VGA_HEIGHT passed the check, so the next terminal_putentryat() could write at index row * 80 + 80 -- one cell past the end of the line, and past the end of the VGA text buffer when already on the last row.

x == VGA_WIDTH and y == VGA_HEIGHT passed the check, so the next
terminal_putentryat() could write at index row * 80 + 80 -- one cell
past the end of the line, and past the end of the VGA text buffer
when already on the last row.
@kudasaixc

Copy link
Copy Markdown
Contributor Author

PoC

terminal_set_cursor clamps with > instead of >=:

if (x > VGA_WIDTH)  x = VGA_WIDTH - 1;   // 80 > 80 is false -> x stays 80
if (y > VGA_HEIGHT) y = VGA_HEIGHT - 1;  // 25 > 25 is false -> y stays 25

The ANSI H handler passes 0-based x-1, y-1, so an escape asking for column 81 / row 25 slips straight through the clamp. This is reachable from anything printed to the terminal — e.g. echo:

echo \x1b[25;81H

drives terminal_set_cursor(80, 24); x = 80 == VGA_WIDTH is not caught, so the next character is written at:

index = row * VGA_WIDTH + col = 24 * 80 + 80 = 2000

The VGA text buffer holds 80 * 25 = 2000 cells (valid indices 0–1999), so index 2000 is one past the end — an out-of-bounds write into whatever MMIO/memory follows 0xB8000. Fix uses >=.

@im-nymii

Copy link
Copy Markdown
Member

LGTM

@im-nymii
im-nymii merged commit 8c67be3 into Auri-OS:develop Jul 24, 2026
3 checks 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