csi: fix parsing of 256-color and 24-bit color SGRs

There may be more SGR sequences after the 256-color/24-bit
sequence. Thus, check that we have *enough* parameters to parse the
256-color/24-bit SGR. It doesn't have to be *exactly* the required
number of parameters though.

Fixes issues with sequences like: \e[38;2;1;48;2;1m
This commit is contained in:
Daniel Eklöf 2019-07-04 09:57:02 +02:00
parent ef944933e6
commit 0457c33418
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

8
csi.c
View file

@ -139,14 +139,14 @@ csi_sgr(struct terminal *term)
break;
case 38: {
if (term->vt.params.idx - i - 1 == 2 &&
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;
term->vt.attrs.foreground = colors256[idx];
term->vt.attrs.have_foreground = true;
i += 2;
} else if (term->vt.params.idx - i - 1 == 4 &&
} else if (term->vt.params.idx - i - 1 >= 4 &&
term->vt.params.v[i + 1].value == 2)
{
uint8_t r = term->vt.params.v[i + 2].value;
@ -185,14 +185,14 @@ csi_sgr(struct terminal *term)
break;
case 48: {
if (term->vt.params.idx - i - 1 == 2 &&
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;
term->vt.attrs.background = colors256[idx];
term->vt.attrs.have_background = true;
i += 2;
} else if (term->vt.params.idx - i - 1 == 4 &&
} else if (term->vt.params.idx - i - 1 >= 4 &&
term->vt.params.v[i + 1].value == 2)
{
uint8_t r = term->vt.params.v[i + 2].value;