From 4f0c0628a20f89c6238f1f360273ae2556901727 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 5 Apr 2021 21:06:48 +0200 Subject: osc: verify OSC 4/104 color index is valid Closes #434 --- osc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'osc.c') diff --git a/osc.c b/osc.c index bf97db52..68783701 100644 --- a/osc.c +++ b/osc.c @@ -575,6 +575,11 @@ osc_dispatch(struct terminal *term) idx += c - '0'; } + if (idx >= ALEN(term->colors.table)) { + LOG_WARN("invalid OSC 4 color index: %u", idx); + break; + } + /* Client queried for current value */ if (strlen(s_color) == 1 && s_color[0] == '?') { uint32_t color = term->colors.table[idx]; @@ -698,7 +703,7 @@ osc_dispatch(struct terminal *term) if (strlen(string) == 0) { LOG_DBG("resetting all colors"); - for (size_t i = 0; i < 256; i++) { + for (size_t i = 0; i < ALEN(term->colors.table); i++) { update_color_in_grids( term, term->colors.table[i], term->colors.default_table[i]); term->colors.table[i] = term->colors.default_table[i]; @@ -717,6 +722,11 @@ osc_dispatch(struct terminal *term) idx += c - '0'; } + if (idx >= ALEN(term->colors.table)) { + LOG_WARN("invalid OSC 104 color index: %u", idx); + continue; + } + LOG_DBG("resetting color #%u", idx); update_color_in_grids( term, term->colors.table[idx], term->colors.default_table[idx]); -- cgit v1.3