aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2022-10-25 17:11:11 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2022-10-25 17:11:11 +0200
commite5e959835b195c023d1f685ef4dbbcfc3b5120b2 (patch)
treeb289ec06a3774611210e1f2a5dc1581b1d3cdae6
parent68d1ad9b54e952e3079356aeab8ab37e44c56c2c (diff)
downloadst-patched-e5e959835b195c023d1f685ef4dbbcfc3b5120b2.tar.bz2
st-patched-e5e959835b195c023d1f685ef4dbbcfc3b5120b2.tar.xz
st-patched-e5e959835b195c023d1f685ef4dbbcfc3b5120b2.zip
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 2a3bd38..aa09997 100644
--- a/x.c
+++ b/x.c
@@ -1833,7 +1833,7 @@ void
1833kpress(XEvent *ev) 1833kpress(XEvent *ev)
1834{ 1834{
1835 XKeyEvent *e = &ev->xkey; 1835 XKeyEvent *e = &ev->xkey;
1836 KeySym ksym; 1836 KeySym ksym = NoSymbol;
1837 char buf[64], *customkey; 1837 char buf[64], *customkey;
1838 int len; 1838 int len;
1839 Rune c; 1839 Rune c;
@@ -1843,10 +1843,13 @@ kpress(XEvent *ev)
1843 if (IS_SET(MODE_KBDLOCK)) 1843 if (IS_SET(MODE_KBDLOCK))
1844 return; 1844 return;
1845 1845
1846 if (xw.ime.xic) 1846 if (xw.ime.xic) {
1847 len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status); 1847 len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status);
1848 else 1848 if (status == XBufferOverflow)
1849 return;
1850 } else {
1849 len = XLookupString(e, buf, sizeof buf, &ksym, NULL); 1851 len = XLookupString(e, buf, sizeof buf, &ksym, NULL);
1852 }
1850 /* 1. shortcuts */ 1853 /* 1. shortcuts */
1851 for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) { 1854 for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
1852 if (ksym == bp->keysym && match(bp->mod, e->state)) { 1855 if (ksym == bp->keysym && match(bp->mod, e->state)) {