aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2022-10-25 17:11:11 +0200
committerRomain Gonçalves <me@rgoncalves.se>2024-05-12 21:20:51 +0200
commitb9d62df040a41a3b192a71932beaea5bd2136c62 (patch)
tree56e461867dceb22779b982d08590b5167397afe8
parent69eff595d492e7f25a452a4a222d7ca578cd3bdd (diff)
downloadst-b9d62df040a41a3b192a71932beaea5bd2136c62.tar.gz
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: [...] <question> <T> <E> <S> <T> <question> : "1234567890123456789012345678901234567890123456789012345678901234567890" " Reported by and an initial patch by Andy Gozas <andy@gozas.me>, 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.
-rw-r--r--x.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/x.c b/x.c
index 552e1c9..f683ac5 100644
--- a/x.c
+++ b/x.c
@@ -1936,7 +1936,7 @@ void
kpress(XEvent *ev)
{
XKeyEvent *e = &ev->xkey;
- KeySym ksym;
+ KeySym ksym = NoSymbol;
char buf[64], *customkey;
int len;
Rune c;
@@ -1946,10 +1946,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)) {
remember that computers suck.