From 6a576f012184b9c2dba9117ad870cab1bd012818 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 12 Aug 2018 22:37:24 -0700 Subject: [PATCH] GUACAMOLE-610: Limit terminal width/height to 1024 characters. --- src/terminal/terminal.c | 35 +++++++++++++++++++++++++++++--- src/terminal/terminal/terminal.h | 11 ++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index ae34fddb..44477894 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -590,13 +590,29 @@ guac_terminal* guac_terminal_create(guac_client* client, term->default_char = default_char; term->clipboard = clipboard; + /* Calculate character size */ + int rows = height / term->display->char_height; + int columns = available_width / term->display->char_width; + + /* Keep height within predefined maximum */ + if (rows > GUAC_TERMINAL_MAX_ROWS) { + rows = GUAC_TERMINAL_MAX_ROWS; + height = rows * term->display->char_height; + } + + /* Keep width within predefined maximum */ + if (columns > GUAC_TERMINAL_MAX_COLUMNS) { + columns = GUAC_TERMINAL_MAX_COLUMNS; + available_width = columns * term->display->char_width; + width = available_width + GUAC_TERMINAL_SCROLLBAR_WIDTH; + } + /* Set pixel size */ term->width = width; term->height = height; - /* Calculate character size */ - term->term_width = available_width / term->display->char_width; - term->term_height = height / term->display->char_height; + term->term_width = columns; + term->term_height = rows; /* Open STDIN pipe */ if (pipe(term->stdin_pipe_fd)) { @@ -1508,6 +1524,19 @@ int guac_terminal_resize(guac_terminal* terminal, int width, int height) { int rows = height / display->char_height; int columns = available_width / display->char_width; + /* Keep height within predefined maximum */ + if (rows > GUAC_TERMINAL_MAX_ROWS) { + rows = GUAC_TERMINAL_MAX_ROWS; + height = rows * display->char_height; + } + + /* Keep width within predefined maximum */ + if (columns > GUAC_TERMINAL_MAX_COLUMNS) { + columns = GUAC_TERMINAL_MAX_COLUMNS; + available_width = columns * display->char_width; + width = available_width + GUAC_TERMINAL_SCROLLBAR_WIDTH; + } + /* Set pixel sizes */ terminal->width = width; terminal->height = height; diff --git a/src/terminal/terminal/terminal.h b/src/terminal/terminal/terminal.h index f1532525..42a741a9 100644 --- a/src/terminal/terminal/terminal.h +++ b/src/terminal/terminal/terminal.h @@ -37,6 +37,17 @@ #include #include +/** + * The absolute maximum number of rows to allow within the display. + */ +#define GUAC_TERMINAL_MAX_ROWS 1024 + +/** + * The absolute maximum number of columns to allow within the display. This + * implicitly limits the number of columns allowed within the buffer. + */ +#define GUAC_TERMINAL_MAX_COLUMNS 1024 + /** * The maximum duration of a single frame, in milliseconds. */