From ab09d1f56f5881eb5d2234038d9146f74deecc10 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Mon, 1 Jul 2024 15:50:23 +0200 Subject: Terminal: Avoid out of bounds access on resize --- userland/terminal/term.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'userland') diff --git a/userland/terminal/term.c b/userland/terminal/term.c index bff6eab..abb150c 100644 --- a/userland/terminal/term.c +++ b/userland/terminal/term.c @@ -5,16 +5,16 @@ #include #include #include -#include #include #include #include #include +#include #include #define TERM_BACKGROUND 0x000000 -char terminal_char_buffer[1920 / 8][1080 / 8] = {0}; +char terminal_char_buffer[1080 / 8][1920 / 8] = {0}; int cmdfd; GUI_Window *global_w; @@ -230,8 +230,14 @@ void handle_escape_codes_or_print(char *buffer, int len) { void terminal_resize(uint32_t sx, uint32_t sy) { assert(GUI_BufferResize(global_w, sx, sy)); for (int y = 0; y < sy; y += 8) { + if (y / 8 >= 1080 / 8) { + break; + } int x = 0; for (; x < sx; x += 8) { + if (x / 8 >= 1920 / 8) { + break; + } GUI_DrawFont(global_w, x, y, terminal_char_buffer[y / 8][x / 8]); } } -- cgit v1.2.3