aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoname <noname@inventati.org>2014-04-23 02:08:13 +0400
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2014-04-25 17:17:48 +0200
commit80b32af794b659cb15745cfb2a19fce0829c42c7 (patch)
tree3991d7b4a03f0eafda64222adb8b7dc1868cb48a
parent16ac85bf5422a7e925743f6134572d3ac1a25188 (diff)
downloadst-80b32af794b659cb15745cfb2a19fce0829c42c7.tar.gz
st-80b32af794b659cb15745cfb2a19fce0829c42c7.zip
Simplify tdeletechar and tinsertblank and fix memory corruption.
Current CSI parsing code uses strtol to parse arguments and allows them to be negative. Negative argument is not properly handled in tdeletechar and tinsertblank and results in memory corruption in memmove. Reproduce with printf '\e[-500@' Patch also removes special handling for corner case and simplifies the code. Removed term.dirty[term.c.y] = 1 because tclearregion sets dirty flag.
-rw-r--r--st.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/st.c b/st.c
index 60243a7..263abaa 100644
--- a/st.c
+++ b/st.c
@@ -1586,37 +1586,31 @@ tclearregion(int x1, int y1, int x2, int y2) {
1586 1586
1587void 1587void
1588tdeletechar(int n) { 1588tdeletechar(int n) {
1589 int src = term.c.x + n; 1589 int dst, src, size;
1590 int dst = term.c.x;
1591 int size = term.col - src;
1592 1590
1593 term.dirty[term.c.y] = 1; 1591 LIMIT(n, 0, term.col - term.c.x);
1594 1592
1595 if(src >= term.col) { 1593 dst = term.c.x;
1596 tclearregion(term.c.x, term.c.y, term.col-1, term.c.y); 1594 src = term.c.x + n;
1597 return; 1595 size = term.col - src;
1598 }
1599 1596
1600 memmove(&term.line[term.c.y][dst], &term.line[term.c.y][src], 1597 memmove(&term.line[term.c.y][dst], &term.line[term.c.y][src],
1601 size * sizeof(Glyph)); 1598 size * sizeof(Glyph));
1602 tclearregion(term.col-n, term.c.y, term.col-1, term.c.y); 1599 tclearregion(term.col-n, term.c.y, term.col-1, term.c.y);
1603} 1600}
1604 1601
1605void 1602void
1606tinsertblank(int n) { 1603tinsertblank(int n) {
1607 int src = term.c.x; 1604 int dst, src, size;
1608 int dst = src + n;
1609 int size = term.col - dst;
1610 1605
1611 term.dirty[term.c.y] = 1; 1606 LIMIT(n, 0, term.col - term.c.x);
1612 1607
1613 if(dst >= term.col) { 1608 dst = term.c.x + n;
1614 tclearregion(term.c.x, term.c.y, term.col-1, term.c.y); 1609 src = term.c.x;
1615 return; 1610 size = term.col - dst;
1616 }
1617 1611
1618 memmove(&term.line[term.c.y][dst], &term.line[term.c.y][src], 1612 memmove(&term.line[term.c.y][dst], &term.line[term.c.y][src],
1619 size * sizeof(Glyph)); 1613 size * sizeof(Glyph));
1620 tclearregion(src, term.c.y, dst - 1, term.c.y); 1614 tclearregion(src, term.c.y, dst - 1, term.c.y);
1621} 1615}
1622 1616