From 6f5587b02ace03683de4e132ff9b57e3410de5dc Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 11 Sep 2025 12:40:44 +0000 Subject: [PATCH] Fix NULL ptr deref in `ipc_describe_workspace` When hot-plugging monitor(s) `ipc_json_describe_workspace` can end up dereferencing a NULL ptr in `wlr_output->name`. Here we simply check that it is set. While this is probably a race and just checking that it is not NULL before accessing it won't fully solve the race, it should make it substantially more rare. Mostly addresses #8747 --- sway/ipc-json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 3b69ad38..8e3634bb 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -516,8 +516,9 @@ static void ipc_json_describe_workspace(struct sway_workspace *workspace, } json_object_object_add(object, "num", json_object_new_int(num)); json_object_object_add(object, "fullscreen_mode", json_object_new_int(1)); - json_object_object_add(object, "output", workspace->output ? - json_object_new_string(workspace->output->wlr_output->name) : NULL); + json_object_object_add(object, "output", + workspace->output && workspace->output->wlr_output->name ? + json_object_new_string(workspace->output->wlr_output->name) : NULL); json_object_object_add(object, "urgent", json_object_new_boolean(workspace->urgent)); json_object_object_add(object, "representation", workspace->representation ?