add some range checks for ATTR_WIDE and ATTR_WDUMMY

The handling for ATTR_WIDE and ATTR_WDUMMY might be incomplete and need more
work. This is a quick fix to at least not allow out of bounds writes.

To reproduce:

	printf '\u4e00\r\033[PA'

Reported by: jb19357 <jb19357@protonmail.com>

Thanks!
This commit is contained in:
Hiltjo Posthuma committed 2026-10-16 13:10:59 +02:00
1 parent 3caed3e78f
commit 2f02c153d5
1 file changed
+6 -4
+6 -4
View File
@@ -1219,8 +1219,10 @@ tsetchar(Rune u, const Glyph *attr, int x, int y)
term.line[y][x+1].mode &= ~ATTR_WDUMMY;
}
} else if (term.line[y][x].mode & ATTR_WDUMMY) {
term.line[y][x-1].u = ' ';
term.line[y][x-1].mode &= ~ATTR_WIDE;
if (x > 0) {
term.line[y][x-1].u = ' ';
term.line[y][x-1].mode &= ~ATTR_WIDE;
}
}
term.dirty[y] = 1;
@@ -2687,9 +2689,9 @@ draw(void)
/* adjust cursor position */
LIMIT(term.ocx, 0, term.col-1);
LIMIT(term.ocy, 0, term.row-1);
if (term.line[term.ocy][term.ocx].mode & ATTR_WDUMMY)
if (term.ocx > 0 && (term.line[term.ocy][term.ocx].mode & ATTR_WDUMMY))
term.ocx--;
if (term.line[term.c.y][cx].mode & ATTR_WDUMMY)
if (cx > 0 && (term.line[term.c.y][cx].mode & ATTR_WDUMMY))
cx--;
drawregion(0, 0, term.col, term.row);