From f28319be54871d56dcd98a02ce9586e0e302ad5d Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Mon, 3 Jan 2022 05:38:48 +0100 Subject: [PATCH] config/keybind.c: Don't overwrite the stack --- include/config/keybind.h | 2 ++ src/config/keybind.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/config/keybind.h b/include/config/keybind.h index fcb4bc83..78caf9a3 100644 --- a/include/config/keybind.h +++ b/include/config/keybind.h @@ -5,6 +5,8 @@ #include #include +#define MAX_KEYSYMS 32 + struct keybind { uint32_t modifiers; xkb_keysym_t *keysyms; diff --git a/src/config/keybind.c b/src/config/keybind.c index 3ef925da..3a6066ee 100644 --- a/src/config/keybind.c +++ b/src/config/keybind.c @@ -28,7 +28,7 @@ struct keybind * keybind_create(const char *keybind) { struct keybind *k = calloc(1, sizeof(struct keybind)); - xkb_keysym_t keysyms[32]; + xkb_keysym_t keysyms[MAX_KEYSYMS]; gchar **symnames = g_strsplit(keybind, "-", -1); for (int i = 0; symnames[i]; i++) { char *symname = symnames[i]; @@ -46,6 +46,12 @@ keybind_create(const char *keybind) } keysyms[k->keysyms_len] = sym; k->keysyms_len++; + if (k->keysyms_len == MAX_KEYSYMS) { + wlr_log(WLR_ERROR, "There are a lot of fingers involved. " + "We stopped counting at %u.", MAX_KEYSYMS); + wlr_log(WLR_ERROR, "Offending keybind was %s", keybind); + break; + } } } g_strfreev(symnames);