Skip to content

Commit 02b3c6f

Browse files
committed
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: validate height along with width. fixes #8619 collect errors of all cmd_resize variations and bubble them up Log invalid command usage without this, the invalid command usages from the config criteria do not get logged or printed to the user anywhere.
1 parent 583862e commit 02b3c6f

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

Diff for: sway/commands.c

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ list_t *execute_command(char *_exec, struct sway_seat *seat,
295295
struct cmd_results *res = handler->handle(argc-1, argv+1);
296296
list_add(res_list, res);
297297
if (res->status == CMD_INVALID) {
298+
sway_log(SWAY_ERROR, "%s", res->error);
298299
free_argv(argc, argv);
299300
goto cleanup;
300301
}

Diff for: sway/commands/resize.c

+7-11
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ static struct cmd_results *cmd_resize_set(int argc, char **argv) {
457457
if (argc > num_consumed_args) {
458458
return cmd_results_new(CMD_INVALID, "%s", usage);
459459
}
460-
if (width.unit == MOVEMENT_UNIT_INVALID) {
460+
if (height.unit == MOVEMENT_UNIT_INVALID) {
461461
return cmd_results_new(CMD_INVALID, "%s", usage);
462462
}
463463
}
@@ -582,17 +582,13 @@ struct cmd_results *cmd_resize(int argc, char **argv) {
582582
}
583583

584584
if (strcasecmp(argv[0], "set") == 0) {
585-
return cmd_resize_set(argc - 1, &argv[1]);
585+
error = cmd_resize_set(argc - 1, &argv[1]);
586586
}
587-
if (strcasecmp(argv[0], "grow") == 0) {
588-
return cmd_resize_adjust(argc - 1, &argv[1], 1);
587+
else if (strcasecmp(argv[0], "grow") == 0) {
588+
error = cmd_resize_adjust(argc - 1, &argv[1], 1);
589589
}
590-
if (strcasecmp(argv[0], "shrink") == 0) {
591-
return cmd_resize_adjust(argc - 1, &argv[1], -1);
590+
else if (strcasecmp(argv[0], "shrink") == 0) {
591+
error = cmd_resize_adjust(argc - 1, &argv[1], -1);
592592
}
593-
594-
const char usage[] = "Expected 'resize <shrink|grow> "
595-
"<width|height|up|down|left|right> [<amount>] [px|ppt]'";
596-
597-
return cmd_results_new(CMD_INVALID, "%s", usage);
593+
return error;
598594
}

0 commit comments

Comments
 (0)