From c076f03dc49335a72e78c3b8a31f58edba1e5857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 18 Dec 2021 20:39:08 +0100 Subject: [PATCH 1/2] config: error out on empty key- or mouse binding Closes #851 --- CHANGELOG.md | 2 ++ config.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1904fd5d..9a972955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,8 @@ CSI codes in the Kitty keyboard protocol. * Assertion in `shm.c:buffer_release()` (https://codeberg.org/dnkl/foot/issues/844). +* Crash when setting a key- or mouse binding to the empty string + (https://codeberg.org/dnkl/foot/issues/851). ### Security diff --git a/config.c b/config.c index 50fb74e6..2b7ad378 100644 --- a/config.c +++ b/config.c @@ -1726,6 +1726,12 @@ value_to_key_combos(struct context *ctx, int action, struct argv *argv, } + if (idx == 0) { + LOG_CONTEXTUAL_ERR( + "empty binding not allowed (set to 'none' to unmap)"); + goto err; + } + remove_from_key_bindings_list(bindings, action, argv); bindings->arr = xrealloc( From 454d4e22aaab3a7d4be3c1fe2f291630a952b1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 18 Dec 2021 20:42:37 +0100 Subject: [PATCH 2/2] test: config: verify setting an empty key/mouse binding fails --- tests/test-config.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test-config.c b/tests/test-config.c index 1e99b3c4..6a2edcb8 100644 --- a/tests/test-config.c +++ b/tests/test-config.c @@ -296,7 +296,16 @@ test_key_binding(struct context *ctx, bool (*parse_fun)(struct context *ctx), const int click_count = action % 3 + 1; /* Finally, generate the ‘value’ (e.g. “Control+shift+x”) */ - char value[128]; + char value[128] = {0}; + + ctx->key = key; + ctx->value = value; + + /* First, try setting the empty string */ + if (parse_fun(ctx)) { + BUG("[%s].%s=: did not fail to parse as expected", + ctx->section, ctx->key); + } switch (type) { case KEY_BINDING: { @@ -319,9 +328,6 @@ test_key_binding(struct context *ctx, bool (*parse_fun)(struct context *ctx), } } - ctx->key = key; - ctx->value = value; - if (!parse_fun(ctx)) { BUG("[%s].%s=%s failed to parse", ctx->section, ctx->key, ctx->value);