From b3af741cd07b1a62ff367da29c1ae90e84f0a508 Mon Sep 17 00:00:00 2001 From: Raheman Vaiya Date: Sat, 27 Aug 2022 17:01:10 -0400 Subject: [PATCH] bind: Add missing NULL terminator --- src/daemon.c | 9 ++++++++- src/keyd.c | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/daemon.c b/src/daemon.c index 2da469c..8fa16a1 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -213,7 +213,7 @@ static void send_success(int con) struct ipc_message msg; msg.type = IPC_SUCCESS;; - msg.sz = sprintf(msg.data, "Success"); + msg.sz = 0; xwrite(con, &msg, sizeof msg); close(con); @@ -255,6 +255,13 @@ static void handle_client(int con) case IPC_BIND: success = 0; + if (msg.sz == sizeof(msg.data)) { + send_fail(con, "bind expression size exceeded"); + return; + } + + msg.data[msg.sz] = 0; + for (ent = configs; ent; ent = ent->next) { if (!kbd_eval(ent->kbd, msg.data)) success = 1; diff --git a/src/keyd.c b/src/keyd.c index af412f5..c362f8e 100644 --- a/src/keyd.c +++ b/src/keyd.c @@ -80,7 +80,7 @@ static int list_keys(int argc, char *argv[]) } -static int add_binding(int argc, char *argv[]) +static int add_bindings(int argc, char *argv[]) { int i; int ret = 0; @@ -90,6 +90,9 @@ static int add_binding(int argc, char *argv[]) ret = -1; } + if (!ret) + printf("Success\n"); + return ret; } @@ -137,7 +140,7 @@ struct { /* Keep -e and -m for backward compatibility. TODO: remove these at some point. */ {"monitor", "-m", "--monitor", monitor}, - {"bind", "-e", "--expression", add_binding}, + {"bind", "-e", "--expression", add_bindings}, {"listen", "", "", layer_listen},