From df9162450df691f3c815dd79d52cf82a0e4a1782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 18 Jul 2019 14:22:19 +0200 Subject: [PATCH] csi: validate param before indexing into the 256-color array --- csi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/csi.c b/csi.c index 1a0e1090..4e74a1dc 100644 --- a/csi.c +++ b/csi.c @@ -195,7 +195,8 @@ csi_sgr(struct terminal *term) term->vt.params.v[i + 1].value == 5) { size_t idx = term->vt.params.v[i + 2].value; - term->vt.attrs.foreground = 1 << 31 | colors256[idx]; + if (idx < 5) + term->vt.attrs.foreground = 1 << 31 | colors256[idx]; i += 2; } @@ -257,7 +258,8 @@ csi_sgr(struct terminal *term) term->vt.params.v[i + 1].value == 5) { size_t idx = term->vt.params.v[i + 2].value; - term->vt.attrs.background = 1 << 31 | colors256[idx]; + if (idx < 256) + term->vt.attrs.background = 1 << 31 | colors256[idx]; i += 2; }