From d302b541f7be5fb3d450634ae29a68c262e4949c Mon Sep 17 00:00:00 2001 From: Furkan Sahin Date: Mon, 31 Mar 2025 20:37:37 -0400 Subject: [PATCH] sway/commands: Handle incorrect resize unit problem: an invalid usage of the command `resize set` will cause sway to crash because it doesn't check for an invalid height. solution: 1. validate height along with width 2. collect all the resize returns into a var in order to log potential errors before returning, so the user has more context as to why the resize config did not work. fixes #8619 --- sway/commands/resize.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 32b746ea..8caa4331 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -457,7 +456,7 @@ static struct cmd_results *cmd_resize_set(int argc, char **argv) { if (argc > num_consumed_args) { return cmd_results_new(CMD_INVALID, "%s", usage); } - if (width.unit == MOVEMENT_UNIT_INVALID) { + if (height.unit == MOVEMENT_UNIT_INVALID) { return cmd_results_new(CMD_INVALID, "%s", usage); } } @@ -582,17 +581,16 @@ struct cmd_results *cmd_resize(int argc, char **argv) { } if (strcasecmp(argv[0], "set") == 0) { - return cmd_resize_set(argc - 1, &argv[1]); + error = cmd_resize_set(argc - 1, &argv[1]); } - if (strcasecmp(argv[0], "grow") == 0) { - return cmd_resize_adjust(argc - 1, &argv[1], 1); + else if (strcasecmp(argv[0], "grow") == 0) { + error = cmd_resize_adjust(argc - 1, &argv[1], 1); } - if (strcasecmp(argv[0], "shrink") == 0) { - return cmd_resize_adjust(argc - 1, &argv[1], -1); + else if (strcasecmp(argv[0], "shrink") == 0) { + error = cmd_resize_adjust(argc - 1, &argv[1], -1); } - - const char usage[] = "Expected 'resize " - " [] [px|ppt]'"; - - return cmd_results_new(CMD_INVALID, "%s", usage); + if (error->status == CMD_INVALID) { + sway_log(SWAY_ERROR, "Invalid resize command: '%s'", error->error); + } + return error; }