From 72b1a6ed7da07e08e677c4718aff945c374ddc10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net>
Date: Sun, 5 Jan 2025 00:16:48 -0500
Subject: [PATCH] Avoid read out of bounds in bad CSI m

In the CSI 38 : 2 : Z? : R : G : B m variant, if there was no
sub params (ie: CSI 38 : m), a read out of bounds would be
triggered.
Found by scan-build
---
 src/conio/cterm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conio/cterm.c b/src/conio/cterm.c
index a8a7fdf829..55f3fb58bc 100644
--- a/src/conio/cterm.c
+++ b/src/conio/cterm.c
@@ -2427,7 +2427,7 @@ static void parse_extended_colour(struct esc_seq *seq, int *i, struct cterminal
 				*co = sub.param_int[2];
 				save_extended_colour_seq(cterm, fg, seq, *i, 1);
 			}
-			else if (sub.param_int[1] == 2) {
+			else if (sub.param_count >= 5 && sub.param_int[1] == 2) {
 				if (sub.param_count == 5) {
 					nc = map_rgb(sub.param_int[2]<<8, sub.param_int[3]<<8, sub.param_int[4]<<8);
 					if (nc != UINT32_MAX)
-- 
GitLab