From a614fe615f931c3a253333ecad9be8f3a671669f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 5 Nov 2017 10:17:40 +0530 Subject: [PATCH] Improve error reporting of incomplete SGR codes --- kitty/parser.c | 18 ++++++++++++++---- kitty_tests/parser.py | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/kitty/parser.c b/kitty/parser.c index bccd849e6..7117d1fbe 100644 --- a/kitty/parser.c +++ b/kitty/parser.c @@ -487,13 +487,23 @@ parse_sgr(Screen *screen, uint32_t *buf, unsigned int num, unsigned int *params, SEND_SGR; break; case COLOR1: - case COLOR3: case NORMAL: case MULTIPLE: - READ_PARAM; - SEND_SGR; + if (i > num_start) { READ_PARAM; } + if (num_params) { SEND_SGR; } + else { REPORT_ERROR("Incomplete SGR code"); } break; - default: + case COLOR: + REPORT_ERROR("Invalid SGR code containing incomplete semi-colon separated color sequence"); + break; + case COLOR3: + if (i > num_start) READ_PARAM; + if (num_params != 5) { + REPORT_ERROR("Invalid SGR code containing incomplete semi-colon separated color sequence"); + break; + } + if (num_params) { SEND_SGR; } + else { REPORT_ERROR("Incomplete SGR code"); } break; } #undef READ_PARAM diff --git a/kitty_tests/parser.py b/kitty_tests/parser.py index 0cb907641..28813428f 100644 --- a/kitty_tests/parser.py +++ b/kitty_tests/parser.py @@ -136,6 +136,7 @@ class TestParser(BaseTest): pb('\033[m', *sgr('0 ')) pb('\033[1;;2m', *sgr('1 0 2')) pb('\033[38;5;1m', ('select_graphic_rendition', '38 5 1 ')) + pb('\033[58;2;1;2;3m', ('select_graphic_rendition', '58 2 1 2 3 ')) pb('\033[38;2;1;2;3m', ('select_graphic_rendition', '38 2 1 2 3 ')) pb('\033[1001:2:1:2:3m', ('select_graphic_rendition', '1001 2 1 2 3 ')) pb('\033[38:2:1:2:3;48:5:9;58;5;7m', (