aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-01-31 13:03:36 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-01-31 13:03:36 +0900
commit71f1fdc66c8ef0d05b2e3351f9cb9e5ce98d2be3 (patch)
treefb43d32726df93891c9f39652fad578547fa165c
parentlet's start a new development cycle (diff)
downloadterminology-71f1fdc66c8ef0d05b2e3351f9cb9e5ce98d2be3.tar.gz
terminology tabs resize - fix access of invalid memory beyond bounds
we memcpy'd the currenty size over, so if prev size was smaller - this was wrong and valgrind threw a complaint. also the rounding seems utterly bizarre. it looks like it was meant to round up to the nearest "lot of 8 tabs" so actually do that... which makes is easy to pass in old width nicely now to fix the problem. @fix
-rw-r--r--src/bin/termpty.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 99a53e4..30ee96a 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -348,23 +348,23 @@ _limit_coord(Termpty *ty)
}
static void
-_termpty_resize_tabs(Termpty *ty, int new_w)
+_termpty_resize_tabs(Termpty *ty, int old_w, int new_w)
{
unsigned int *new_tabs;
int i;
- size_t nb_elems;
+ size_t nb_elems, n;
- if (new_w == ty->w && ty->tabs)
- return;
+ if ((new_w == old_w) && ty->tabs) return;
- nb_elems = DIV_ROUND_UP(new_w, sizeof(unsigned int) * 8);
+ nb_elems = ROUND_UP(new_w, 8);
new_tabs = calloc(nb_elems, sizeof(unsigned int));
- if (!new_tabs)
- return;
+ if (!new_tabs) return;
if (ty->tabs)
{
- memcpy(new_tabs, ty->tabs, nb_elems * sizeof(unsigned int));
+ n = old_w;
+ if (nb_elems < n) n = nb_elems;
+ if (n > 0) memcpy(new_tabs, ty->tabs, n * sizeof(unsigned int));
free(ty->tabs);
}
@@ -442,8 +442,7 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
goto err;
}
- ty->tabs = NULL;
- _termpty_resize_tabs(ty, w);
+ _termpty_resize_tabs(ty, 0, w);
termpty_reset_state(ty);
@@ -1253,7 +1252,7 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
}
}
- _termpty_resize_tabs(ty, new_w);
+ _termpty_resize_tabs(ty, old_w, new_w);
if (effective_old_h <= ty->cursor_state.cy)
effective_old_h = ty->cursor_state.cy + 1;