Skip to content

Commit

Permalink
Fix an out of bounds read causing a crash when selecting text with th…
Browse files Browse the repository at this point in the history
…e mouse in the alternate screen mode

Fixes #1578
  • Loading branch information
kovidgoyal committed Jun 12, 2019
1 parent 7091d55 commit 8bf2e09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
---------------------

Expand Down
14 changes: 14 additions & 0 deletions kitty/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8bf2e09

Please sign in to comment.