From 43483d8fee3b61a8dbd2734963597d7fc69c7934 Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Sat, 23 Jan 2016 18:43:39 +0100 Subject: [PATCH 1/2] commands: Fix usage of arrow in assign Signed-off-by: Quentin Glidic --- sway/commands.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sway/commands.c b/sway/commands.c index f63260386..fc3444ee9 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -169,7 +169,10 @@ static struct cmd_results *cmd_assign(int argc, char **argv) { char *criteria = *argv++; - if (strncmp(*argv, "→", 1) == 0) { + if (strncmp(*argv, "→", strlen("→")) == 0) { + if (argc < 3) { + return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); + } argv++; } From 449617f10465f685112415239420affbca9a389f Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Sat, 23 Jan 2016 20:20:24 +0100 Subject: [PATCH 2/2] commands: Fix memory allocation in assign Also use the safer snprintf since we just computed the size. Signed-off-by: Quentin Glidic --- sway/commands.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index fc3444ee9..9f6e50327 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -177,10 +177,10 @@ static struct cmd_results *cmd_assign(int argc, char **argv) { } char *movecmd = "move container to workspace "; - int arglen = strlen(*argv); - char *cmdlist = calloc(1, sizeof(movecmd) + arglen); + int arglen = strlen(movecmd) + strlen(*argv) + 1; + char *cmdlist = calloc(1, arglen); - sprintf(cmdlist, "%s%s", movecmd, *argv); + snprintf(cmdlist, arglen, "%s%s", movecmd, *argv); struct criteria *crit = malloc(sizeof(struct criteria)); crit->crit_raw = strdup(criteria);