term/i386/pc/vga_text: Prevent out-of-bounds writes to VGA text buffer

Coordinates passed to screen_write_char() did not have any checks to
ensure they are not out-of-bounds. This adds an if statement to prevent
out-of-bounds writes to the VGA text buffer.

Signed-off-by: Ryan Cohen <rcohenprogramming@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Ryan Cohen authored and Daniel Kiper committed 2022-12-07 23:38:25 +01:00
1 parent 544fd63f0f
commit 108a3865f4
1 file changed
+1
+1
View File
@@ -63,6 +63,7 @@ static grub_uint8_t cur_color = 0x7;
static void static void
screen_write_char (int x, int y, short c) screen_write_char (int x, int y, short c)
{ {
if (x < COLS && y < ROWS && x >= 0 && y >= 0)
VGA_TEXT_SCREEN[y * COLS + x] = grub_cpu_to_le16 (c); VGA_TEXT_SCREEN[y * COLS + x] = grub_cpu_to_le16 (c);
} }