From ecda5c1df958ac9725b0bcbe2897ec43163aea29 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 16 Jun 2018 23:36:01 -0700 Subject: [PATCH] GUACAMOLE-573: Read selection only within bounds of terminal/scrollback. --- src/terminal/select.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/terminal/select.c b/src/terminal/select.c index 69bb0bc0..131b5f68 100644 --- a/src/terminal/select.c +++ b/src/terminal/select.c @@ -149,6 +149,12 @@ static int guac_terminal_find_char(guac_terminal* terminal, int start_column = *column; + /* If requested row is outside the bounds of the current terminal or + * scrollback, assume the character is 1 column wide */ + if (row >= terminal->term_height + || row < terminal->term_height - terminal->buffer->length) + return 1; + guac_terminal_buffer_row* buffer_row = guac_terminal_buffer_get_row(terminal->buffer, row, 0); if (start_column < buffer_row->length) { @@ -276,7 +282,8 @@ void guac_terminal_select_resume(guac_terminal* terminal, int row, int column) { * @param end * The last column of the text to be copied from the given row into the * clipboard associated with the given terminal, where 0 is the first - * (left-most) column within the row. + * (left-most) column within the row, or a negative value to denote that + * the last column in the row should be used. */ static void guac_terminal_clipboard_append_row(guac_terminal* terminal, int row, int start, int end) { @@ -284,16 +291,22 @@ static void guac_terminal_clipboard_append_row(guac_terminal* terminal, char buffer[1024]; int i = start; + /* If requested row is outside the bounds of the current terminal or + * scrollback, do nothing */ + if (row >= terminal->term_height + || row < terminal->term_height - terminal->buffer->length) + return; + guac_terminal_buffer_row* buffer_row = guac_terminal_buffer_get_row(terminal->buffer, row, 0); /* If selection is entirely outside the bounds of the row, then there is * nothing to append */ - if (start > buffer_row->length - 1) + if (start < 0 || start > buffer_row->length - 1) return; /* Clip given range to actual bounds of row */ - if (end == -1 || end > buffer_row->length - 1) + if (end < 0 || end > buffer_row->length - 1) end = buffer_row->length - 1; /* Repeatedly convert chunks of terminal buffer rows until entire specified