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
This commit is contained in:
Matt Corallo 2025-09-11 12:40:44 +00:00
parent c5456be750
commit 6f5587b02a

View file

@ -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, "num", json_object_new_int(num));
json_object_object_add(object, "fullscreen_mode", json_object_new_int(1)); json_object_object_add(object, "fullscreen_mode", json_object_new_int(1));
json_object_object_add(object, "output", workspace->output ? json_object_object_add(object, "output",
json_object_new_string(workspace->output->wlr_output->name) : NULL); 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_object_add(object, "urgent",
json_object_new_boolean(workspace->urgent)); json_object_new_boolean(workspace->urgent));
json_object_object_add(object, "representation", workspace->representation ? json_object_object_add(object, "representation", workspace->representation ?