Fix an out of bounds read causing a crash when selecting text with the mouse in the alternate screen mode

Fixes #1578
This commit is contained in:
Kovid Goyal 2019-06-12 07:51:10 +05:30
parent 7091d554b5
commit 8bf2e098f5
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 21 additions and 0 deletions

View File

@ -4,6 +4,13 @@ Changelog
|kitty| is a feature full, cross-platform, *fast*, GPU based terminal emulator.
To update |kitty|, :doc:`follow the instructions <binary>`.
0.14.3 [future]
---------------------
- Fix an out of bounds read causing a crash when selecting text with the mouse
in the alternate screen mode (:iss:`1578`)
0.14.2 [2019-06-09]
---------------------

View File

@ -1580,6 +1580,18 @@ range_line_(Screen *self, int y) {
return self->linebuf->line;
}
static inline int
clamp_for_range_line(Screen *self, int y) {
if (y < 0) {
unsigned int idx = -(y + 1);
if (idx >= self->historybuf->count) {
y += idx - self->historybuf->count + 1;
}
return y;
}
return MIN((unsigned int)y, self->lines - 1);
}
#define iterate_over_rectangle(start, end, line_func, y_type) { \
y_type min_y = MIN(start->y, end->y), max_y = MAX(start->y, end->y); \
index_type min_x = MIN(start->x, end->x), max_x = MAX(start->x, end->x); \
@ -1982,6 +1994,8 @@ text_for_selection(Screen *self, PyObject *a UNUSED) {
FullSelectionBoundary start, end;
full_selection_limits_(selection, &start, &end);
PyObject *ans = NULL;
start.y = clamp_for_range_line(self, start.y);
end.y = clamp_for_range_line(self, end.y);
if (start.y == end.y && start.x == end.x) ans = PyTuple_New(0);
else text_for_range(ans, start, end, self->selection.rectangle_select, true, range_line_, int);
return ans;