aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-18 12:25:15 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-18 12:25:15 +0000
commitd5157c15b03fb8ca6067cacac64c6872b23c191c (patch)
treed8a33e863d8652d46b01920adb2c4af427e2362b
parentcsi: validate param before indexing into the 256-color array (diff)
csi: color index is an 8-bit unsigned value
This fixes an issue where a large 8-bit value was signed extended into a large 64-bit value.
-rw-r--r--csi.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/csi.c b/csi.c
index 4e74a1dc..c329a0ea 100644
--- a/csi.c
+++ b/csi.c
@@ -194,9 +194,8 @@ csi_sgr(struct terminal *term)
if (term->vt.params.idx - i - 1 >= 2 &&
term->vt.params.v[i + 1].value == 5)
{
- size_t idx = term->vt.params.v[i + 2].value;
- if (idx < 5)
- term->vt.attrs.foreground = 1 << 31 | colors256[idx];
+ uint8_t idx = term->vt.params.v[i + 2].value;
+ term->vt.attrs.foreground = 1 << 31 | colors256[idx];
i += 2;
}
@@ -257,9 +256,8 @@ csi_sgr(struct terminal *term)
if (term->vt.params.idx - i - 1 >= 2 &&
term->vt.params.v[i + 1].value == 5)
{
- size_t idx = term->vt.params.v[i + 2].value;
- if (idx < 256)
- term->vt.attrs.background = 1 << 31 | colors256[idx];
+ uint8_t idx = term->vt.params.v[i + 2].value;
+ term->vt.attrs.background = 1 << 31 | colors256[idx];
i += 2;
}