From 702a97e296f95ca1fc7ff2e0002d2e97366a86db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 15 Mar 2017 08:53:11 +0100 Subject: ui: add some bound checks --- ui-terminal.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui-terminal.c b/ui-terminal.c index 3b9ac3b..a15f9dd 100644 --- a/ui-terminal.c +++ b/ui-terminal.c @@ -192,6 +192,8 @@ static bool ui_style_define(UiWin *w, int id, const char *style) { } static void ui_style(UiTerm *tui, int x, int y, int len, UiTermWin *win, enum UiStyle style_id) { + if (x < 0 || x >= tui->width || y < 0 || y >= tui->height) + return; CellStyle style = tui->styles[(win ? win->id : 0)*UI_STYLE_MAX + style_id]; Cell (*cells)[tui->width] = (void*)tui->cells; int end = x + len; @@ -203,6 +205,8 @@ static void ui_style(UiTerm *tui, int x, int y, int len, UiTermWin *win, enum Ui static void ui_draw_string(UiTerm *tui, int x, int y, const char *str, UiTermWin *win, enum UiStyle style_id) { debug("draw-string: [%d][%d]\n", y, x); + if (x < 0 || x >= tui->width || y < 0 || y >= tui->height) + return; CellStyle style = tui->styles[(win ? win->id : 0)*UI_STYLE_MAX + style_id]; // FIXME: does not handle double width characters etc, share code with view.c? Cell (*cells)[tui->width] = (void*)tui->cells; -- cgit v1.2.3