Fix crash when encountering incomplete ANSI codes

Add bounds checking before increasing iterator pointer, to prevent
incomplete ANSI codes causing iterators going to far.
This commit is contained in:
Tomas Åkesson 2023-04-02 14:50:38 +02:00 committed by Felix Queißner
parent eecc1d587c
commit d937a0c32e
1 changed files with 6 additions and 6 deletions

View File

@ -159,10 +159,10 @@ static void parseSGR(
format.setFontStrikeOut(false);
break;
case SetForeground:
if (args.size() > 2)
if (args.size() > 2 && std::next(it) != args.cend())
{
const auto colMode = *++it;
if (colMode == 5)
if (colMode == 5 && std::next(it) != args.cend())
{
const auto colNum = *++it;
setColor(format, colNum);
@ -170,7 +170,7 @@ static void parseSGR(
else if (colMode == 2)
{
++it;
if (args.size() >= 4)
if (std::next(it, 3) <= args.cend())
{
const auto red = *it;
const auto green = *++it;
@ -184,10 +184,10 @@ static void parseSGR(
format.setForeground(defaultFormat.foreground());
break;
case SetBackground:
if (args.size() > 2)
if (args.size() > 2 && std::next(it) != args.cend())
{
const auto colMode = *++it;
if (colMode == 5)
if (colMode == 5 && std::next(it) != args.cend())
{
const auto colNum = *++it;
setColor(format, colNum, true);
@ -195,7 +195,7 @@ static void parseSGR(
else if (colMode == 2)
{
++it;
if (args.size() >= 4)
if (std::next(it, 3) <= args.cend())
{
const auto red = *it;
const auto green = *++it;