[PATCH weston] terminal: Fix segmentation fault when processing DCH ANSI escape code
Aaron Hamilton
aaron at correspondwith.me
Sun May 17 00:21:24 PDT 2015
Fixes a segmentation fault when terminal processes a DCH ansi escape code and the cursor is at the end of the row, and terminal_shift_line calls memmove on memory it doesn't own.
---
clients/terminal.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/clients/terminal.c b/clients/terminal.c
index d7345d3..fc9b7ae 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -721,13 +721,16 @@ terminal_shift_line(struct terminal *terminal, int d)
if (d < 0) {
d = 0 - d;
- memmove(&row[terminal->column],
- &row[terminal->column + d],
- (terminal->width - terminal->column - d) * sizeof(union utf8_char));
- memmove(&attr_row[terminal->column], &attr_row[terminal->column + d],
- (terminal->width - terminal->column - d) * sizeof(struct attr));
- memset(&row[terminal->width - d], 0, d * sizeof(union utf8_char));
- attr_init(&attr_row[terminal->width - d], terminal->curr_attr, d);
+
+ if(terminal->width - terminal->column) {
+ memmove(&row[terminal->column],
+ &row[terminal->column + d],
+ (terminal->width - terminal->column - d) * sizeof(union utf8_char));
+ memmove(&attr_row[terminal->column], &attr_row[terminal->column + d],
+ (terminal->width - terminal->column - d) * sizeof(struct attr));
+ memset(&row[terminal->width - d], 0, d * sizeof(union utf8_char));
+ attr_init(&attr_row[terminal->width - d], terminal->curr_attr, d);
+ }
} else {
memmove(&row[terminal->column + d], &row[terminal->column],
(terminal->width - terminal->column - d) * sizeof(union utf8_char));
--
2.4.1
More information about the wayland-devel
mailing list