From 87e4004960265494fcab21c71fff48b4f8b0af33 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 22 Jul 2022 10:44:33 +0200 Subject: csi: clamp color index for ‘CSI 38/48 ; 5 ; idx m’ sequences MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Indexed color values are stored in the cell attributes as color indices (into the 256-color table). However, the index from the CSI was not validated in any way, meaning you can do something like this: echo -e ‘\e[38:5:1024m CRASH \e[m’ and foot will crash on an out-of-bounds access. Fix by clamping the color index. Closes #1111 --- csi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'csi.c') diff --git a/csi.c b/csi.c index 57cae6b3..659839f0 100644 --- a/csi.c +++ b/csi.c @@ -128,7 +128,8 @@ csi_sgr(struct terminal *term) term->vt.params.v[i + 1].value == 5) { src = COLOR_BASE256; - color = term->vt.params.v[i + 2].value; + color = min(term->vt.params.v[i + 2].value, + ALEN(term->colors.table) - 1); i += 2; } @@ -149,7 +150,8 @@ csi_sgr(struct terminal *term) term->vt.params.v[i].sub.value[0] == 5) { src = COLOR_BASE256; - color = term->vt.params.v[i].sub.value[1]; + color = min(term->vt.params.v[i].sub.value[1], + ALEN(term->colors.table) - 1); } /* -- cgit v1.3