diff --git a/src/apps/terminal/TermParse.cpp b/src/apps/terminal/TermParse.cpp index c99e7c1726..adcb2359a5 100644 --- a/src/apps/terminal/TermParse.cpp +++ b/src/apps/terminal/TermParse.cpp @@ -836,12 +836,16 @@ TermParse::EscParse() case 38: { - if (nparam == 3 && param[1] == 5) - attributes.SetIndexedForeground(param[2]); - else if (nparam == 5 && param[1] == 2) - attributes.SetDirectForeground(param[2], param[3], param[4]); + if (nparam >= 3 && param[row+1] == 5) { + attributes.SetIndexedForeground(param[row+2]); + row += 2; + } else if (nparam >= 5 && param[row+1] == 2) { + attributes.SetDirectForeground(param[row+2], param[row+3], param[row+4]); + row += 4; + } else { + row = nparam; // force exit of the parsing + } - row = nparam; // force exit of the parsing break; } @@ -871,12 +875,16 @@ TermParse::EscParse() case 48: { - if (nparam == 3 && param[1] == 5) - attributes.SetIndexedBackground(param[2]); - else if (nparam == 5 && param[1] == 2) - attributes.SetDirectBackground(param[2], param[3], param[4]); + if (nparam >= 3 && param[row+1] == 5) { + attributes.SetIndexedBackground(param[row+2]); + row += 2; + } else if (nparam >= 5 && param[row+1] == 2) { + attributes.SetDirectBackground(param[row+2], param[row+3], param[row+4]); + row += 4; + } else { + row = nparam; // force exit of the parsing + } - row = nparam; // force exit of the parsing break; }