process_ansi assumed all numbers in a color control sequence correspond
to colors or attributes, which breaks badly if it encounters a
ISO-8613-3 escape sequence (such as for truecolor RGB). For instance,
the sequence "\x1b[38;2;10;20;30m" sets the foreground color to
rgb(10,20,30), but watch will interpret all five numbers in the sequence
as colors or attributes themselves.
Stop processing the entire escape sequence if watch encounters any
number it doesn't understand, as that number may change the meaning of
the rest of the sequence.
}
-static void set_ansi_attribute(const int attrib)
+static int set_ansi_attribute(const int attrib)
{
switch (attrib) {
case -1: /* restore last settings */
fg_col = attrib - 30 + 1;
} else if (attrib >= 40 && attrib <= 47) { /* set background color */
bg_col = attrib - 40 + 1;
+ } else {
+ return 0; /* Not understood */
}
}
+ return 1;
attrset(attributes | COLOR_PAIR(bg_col * nr_of_colors + fg_col + 1));
}
set_ansi_attribute(0);
for (endptr = numstart = buf; *endptr != '\0'; numstart = endptr + 1) {
- set_ansi_attribute(strtol(numstart, &endptr, 10));
+ if (!set_ansi_attribute(strtol(numstart, &endptr, 10)))
+ break;
if (numstart == endptr)
set_ansi_attribute(0); /* [m treated as [0m */
}