From 694803663e99299519e1dee88106adfc973c39b3 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 25 Oct 2022 17:11:11 +0200 Subject: fix buffer overflow when handling long composed input To reproduce the issue: " If you already have the multi-key enabled on your system, then add this line to your ~/.XCompose file: [...] : "1234567890123456789012345678901234567890123456789012345678901234567890" " Reported by and an initial patch by Andy Gozas , thanks! Adapted the patch, for now st (like dmenu) handles a fixed amount of composed characters, or otherwise ignores it. This is done for simplicity sake. --- x.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/x.c b/x.c index 26290f6..f6e0b78 100644 --- a/x.c +++ b/x.c @@ -2259,7 +2259,7 @@ void kpress(XEvent *ev) { XKeyEvent *e = &ev->xkey; - KeySym ksym; + KeySym ksym = NoSymbol; char buf[64], *customkey; int len; Rune c; @@ -2269,10 +2269,13 @@ kpress(XEvent *ev) if (IS_SET(MODE_KBDLOCK)) return; - if (xw.ime.xic) + if (xw.ime.xic) { len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status); - else + if (status == XBufferOverflow) + return; + } else { len = XLookupString(e, buf, sizeof buf, &ksym, NULL); + } /* 1. shortcuts */ for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) { if (ksym == bp->keysym && match(bp->mod, e->state)) { -- cgit v1.2.3-70-g09d2