From 84b6913f8ad515b172ad020f96f9d7319593fb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 10 Feb 2023 18:03:46 +0100 Subject: [PATCH] wayland/xdg-foreign: Fix race condition crash We didn't always set an implementation, when the foreign toplevel wasn't found, and when the importer tried to set the parent-child relationship, the implementation was missing and we'd crash in wl_closure_invoke() in libwayland-server. Part-of: --- src/wayland/meta-wayland-legacy-xdg-foreign.c | 14 +++++++++----- src/wayland/meta-wayland-xdg-foreign.c | 17 +++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/wayland/meta-wayland-legacy-xdg-foreign.c b/src/wayland/meta-wayland-legacy-xdg-foreign.c index 7a7bf38c1..583aab333 100644 --- a/src/wayland/meta-wayland-legacy-xdg-foreign.c +++ b/src/wayland/meta-wayland-legacy-xdg-foreign.c @@ -146,6 +146,9 @@ xdg_imported_v1_set_parent_of (struct wl_client *client, { MetaWaylandXdgImported *imported = wl_resource_get_user_data (resource); + if (!imported) + return; + meta_wayland_xdg_imported_set_parent_of (imported, surface_resource); } @@ -197,16 +200,17 @@ xdg_importer_v1_import (struct wl_client *client, imported = meta_wayland_xdg_foreign_import (foreign, xdg_imported_resource, handle, zxdg_imported_v1_send_destroyed); - if (!imported) - { - zxdg_imported_v1_send_destroyed (xdg_imported_resource); - return; - } wl_resource_set_implementation (xdg_imported_resource, &meta_xdg_imported_v1_interface, imported, xdg_imported_v1_destructor); + + if (!imported) + { + zxdg_imported_v1_send_destroyed (xdg_imported_resource); + return; + } } static const struct zxdg_importer_v1_interface meta_xdg_importer_v1_interface = { diff --git a/src/wayland/meta-wayland-xdg-foreign.c b/src/wayland/meta-wayland-xdg-foreign.c index 7c70fa6f2..235d7c431 100644 --- a/src/wayland/meta-wayland-xdg-foreign.c +++ b/src/wayland/meta-wayland-xdg-foreign.c @@ -302,9 +302,6 @@ meta_wayland_xdg_imported_set_parent_of (MetaWaylandXdgImported *imported, { MetaWaylandSurface *surface; - if (!imported) - return; - if (surface_resource) surface = wl_resource_get_user_data (surface_resource); else @@ -348,6 +345,9 @@ xdg_imported_set_parent_of (struct wl_client *client, { MetaWaylandXdgImported *imported = wl_resource_get_user_data (resource); + if (!imported) + return; + meta_wayland_xdg_imported_set_parent_of (imported, surface_resource); } @@ -448,16 +448,17 @@ xdg_importer_import (struct wl_client *client, imported = meta_wayland_xdg_foreign_import (foreign, xdg_imported_resource, handle, zxdg_imported_v2_send_destroyed); - if (!imported) - { - zxdg_imported_v2_send_destroyed (xdg_imported_resource); - return; - } wl_resource_set_implementation (xdg_imported_resource, &meta_xdg_imported_interface, imported, xdg_imported_destructor); + + if (!imported) + { + zxdg_imported_v2_send_destroyed (xdg_imported_resource); + return; + } } static const struct zxdg_importer_v2_interface meta_xdg_importer_interface = {