wayland/outputs: Fix potential crash when output has no monitor

bind_output() creates output interface resource, but does not
set implementation for it when wayland_output->monitor is NULL.
However, when the wayland library is running wl_closure_invoke(),
it expects the implementation to be non-NULL, and if not, it just
segfaults mutter by NULL pointer dereference.

This commit tries to address this issue by setting an implementation
when wayland_output->monitor is NULL. This could help prevent crash
when resuming from suspend or hotplugging displays.

Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2570
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2827>
This commit is contained in:
Keyu Tao 2023-02-06 15:29:47 +08:00 committed by taoky
parent d8ef1b5b8b
commit c1ab3f39d7

View File

@ -317,7 +317,12 @@ bind_output (struct wl_client *client,
monitor = wayland_output->monitor;
if (!monitor)
return;
{
wl_resource_set_implementation (resource,
&meta_wl_output_interface,
NULL, NULL);
return;
}
wayland_output->resources = g_list_prepend (wayland_output->resources,
resource);