From 18a4dddc2b83781f63606e629029059d5cc88965 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Tue, 4 Jun 2024 15:03:17 +0100 Subject: [PATCH] fix: read of uninitialized data at inChar[0] This is a defensive fix, might cause unexpected program exit if triggered. The loop will iterate at least once when nbytes==0, but this value indicates XLookupString did not fill in any data, so the entire buffer is undefined. Using memset() before or inChar[0]=0 after XLookupString did not fix the issue. Using inChar[0]=0 immediately before the loop did fix as well. But this patch seems to be the best approach. --- graphics/grTOGL1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/grTOGL1.c b/graphics/grTOGL1.c index 509a47ca..2feccdf1 100644 --- a/graphics/grTOGL1.c +++ b/graphics/grTOGL1.c @@ -599,7 +599,7 @@ keys_and_buttons: idxmax = (nbytes == 0) ? 1 : nbytes; for (idx = 0; idx < idxmax; idx++) { - if (inChar[idx] == 3) /* Ctrl-C interrupt */ + if (nbytes > 0 && inChar[idx] == 3) /* Ctrl-C interrupt */ { if (SigInterruptPending) MainExit(0); /* double Ctrl-C */