commit d94c8fa

wf  ·  2026-05-29 11:44:54 +0000 UTC
parent 24c093a
Guard against invalid windows in IPC
3 files changed,  +13, -6
+7, -3
 1@@ -113,8 +113,12 @@ ipc_msg(const struct command *cmd, int argc, char **argv) {
 2 	while (*ans == ' ')
 3 		ans++;
 4 
 5-	if (strcmp(ans, "") != 0)
 6-		printf("%s", ans);
 7+	if (strcmp(ans, "") != 0) {
 8+		if (ret == 0)
 9+			fprintf(stderr, "%s", ans);
10+		else
11+			printf("%s", ans);
12+	}
13 	return (int)ret;
14 }
15 
16@@ -126,7 +130,7 @@ main(int argc, char **argv) {
17 	}
18 
19 	for (int i = 0; i < (int)(sizeof commands / sizeof commands[0]); i++) {
20-		if (strcmp(commands[i].name, argv[1]) == 0) {
21+		if (strcmp(argv[1], commands[i].name) == 0) {
22 			if (argc - 2 < commands[i].argc) {
23 				fprintf(stderr, "Wrong number of arguments for %s (need %d)\n", commands[i].name, commands[i].argc);
24 				return 1;
+1, -1
1@@ -804,5 +804,5 @@ main(int argc, char **argv) {
2 		cleanup();
3 
4 	free(conf_path);
5-	return 1;
6+	return 0;
7 }
+5, -2
 1@@ -19,7 +19,7 @@
 2 	struct client *tmp, *c = wm.cur; \
 3 	wl_list_for_each(tmp, &wm.clients, link) \
 4 		if (tmp->id == id) c = tmp; \
 5-	if (!c) return (status){ false, "" }
 6+	if (!c) return (status){ false, "Bad window\n" }
 7 
 8 extern struct wm wm;
 9 extern struct config config;
10@@ -375,7 +375,10 @@ status
11 ipc_get_focus(char **arg) {
12 	status s = {0};
13 
14-	snprintf(s.msg, sizeof(s.msg), "%" PRIu32 "\n", wm.cur->id);
15+	if (wm.cur)
16+		snprintf(s.msg, sizeof(s.msg), "%" PRIu32 "\n", wm.cur->id);
17+	else
18+		return (status){ false, "No window focused\n" };
19 
20 	s.ok = true;
21 	return s;