From 1fe3a96afaa781c2b54f89cbeaaca8c101f2452b Mon Sep 17 00:00:00 2001 From: dam Date: Fri, 8 Dec 2023 03:18:32 +0000 Subject: Fix potential out-of-bounds bug in get_terminal_size and get_cursor_size. --- TUI/module.jai | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TUI/module.jai b/TUI/module.jai index 5157ba2..c8a5512 100644 --- a/TUI/module.jai +++ b/TUI/module.jai @@ -335,11 +335,12 @@ get_terminal_size :: () -> rows: int, columns: int { } // Discard tail noise. - while input.count >= 2 && input[input.count-1] != FORMAT[FORMAT.count-1] { + while input.count >= 3 && input[input.count-1] != FORMAT[FORMAT.count-1] { input.count -= 1; } - assert(input[0] == FORMAT[0] && input[1] == FORMAT[1] && input[2] == FORMAT[2] && input[input.count-1] == FORMAT[FORMAT.count-1], + assert(input.count >= 3 && + input[0] == FORMAT[0] && input[1] == FORMAT[1] && input[2] == FORMAT[2] && input[input.count-1] == FORMAT[FORMAT.count-1], "Query window size in chars returned invalid response."); parts := split(input, ";"); @@ -379,7 +380,8 @@ get_cursor_position :: () -> row: int, column: int { input.count -= 1; } - assert(input[0] == FORMAT[0] && input[1] == FORMAT[1] && input[input.count-1] == FORMAT[FORMAT.count-1], + assert(input.count >= 2 && + input[0] == FORMAT[0] && input[1] == FORMAT[1] && input[input.count-1] == FORMAT[FORMAT.count-1], "Query cursor position returned invalid response."); -- cgit v1.2.3