From 9b3ca29df01c03b551729d05fc51b5911907acee Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 15 Jan 2023 17:49:33 +0000 Subject: [PATCH] ctl-server: Fix segfault in error path This would segfault e.g. if issuing: $ waynvcctl client-disconnect # without argument --- src/ctl-server.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ctl-server.c b/src/ctl-server.c index b511bc5..5607906 100644 --- a/src/ctl-server.c +++ b/src/ctl-server.c @@ -202,7 +202,6 @@ static struct cmd* parse_command(struct jsonipc_request* ipc, case CMD_OUTPUT_LIST: case CMD_OUTPUT_CYCLE: case CMD_WAYVNC_EXIT: - cmd = calloc(1, sizeof(*cmd)); break; case CMD_UNKNOWN: jsonipc_error_set_new(err, ENOENT, @@ -211,9 +210,10 @@ static struct cmd* parse_command(struct jsonipc_request* ipc, jprintf("Unknown command \"%s\"", ipc->method), "commands", list_allowed_commands())); - return NULL; + break; } - cmd->type = cmd_type; + if (cmd) + cmd->type = cmd_type; return cmd; }