[PATCH weston] terminal: Fix segmentation fault when processing DCH ANSI escape code
aaron at correspondwith.me
aaron at correspondwith.me
Sat Jul 2 00:35:21 UTC 2016
Fix a segfault where terminal parses a DCH escape code and the cursor is at the end of the line, causing terminal_shift_line to memmove 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 6257cb7..7a0da29 100644
--- a/clients/terminal.c
+++ b/clients/terminal.c
@@ -724,13 +724,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.9.0
More information about the wayland-devel
mailing list