From 992e169d84d9bef3769da3b0e56bec1d77932379 Mon Sep 17 00:00:00 2001 From: msizanoen1 Date: Sun, 6 Nov 2022 11:38:22 +0700 Subject: [PATCH] wayland/pointer-gestures: Fix crash in get_*_gesture after pointer is destroyed Properly handle cases where the pointer object has already been destroyed to prevent the compositor from crashing with a null pointer dereference when a client invokes a get_*_gesture method after the pointer object is destroyed e.g. when the current login session is not on foreground. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2237 Part-of: --- src/wayland/meta-wayland-pointer-gesture-hold.c | 14 +++++++++----- src/wayland/meta-wayland-pointer-gesture-pinch.c | 14 +++++++++----- src/wayland/meta-wayland-pointer-gesture-swipe.c | 14 +++++++++----- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/wayland/meta-wayland-pointer-gesture-hold.c b/src/wayland/meta-wayland-pointer-gesture-hold.c index 90c63cd25..5ccc42407 100644 --- a/src/wayland/meta-wayland-pointer-gesture-hold.c +++ b/src/wayland/meta-wayland-pointer-gesture-hold.c @@ -139,15 +139,19 @@ meta_wayland_pointer_gesture_hold_create_new_resource (MetaWaylandPointer *point MetaWaylandPointerClient *pointer_client; struct wl_resource *res; - pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client); - g_return_if_fail (pointer_client != NULL); - res = wl_resource_create (client, &zwp_pointer_gesture_hold_v1_interface, wl_resource_get_version (pointer_resource), id); wl_resource_set_implementation (res, &pointer_gesture_hold_interface, pointer, meta_wayland_pointer_unbind_pointer_client_resource); - wl_list_insert (&pointer_client->hold_gesture_resources, - wl_resource_get_link (res)); + + if (pointer) + { + pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client); + g_return_if_fail (pointer_client != NULL); + + wl_list_insert (&pointer_client->hold_gesture_resources, + wl_resource_get_link (res)); + } } void diff --git a/src/wayland/meta-wayland-pointer-gesture-pinch.c b/src/wayland/meta-wayland-pointer-gesture-pinch.c index 32a6bad69..16f106a76 100644 --- a/src/wayland/meta-wayland-pointer-gesture-pinch.c +++ b/src/wayland/meta-wayland-pointer-gesture-pinch.c @@ -170,15 +170,19 @@ meta_wayland_pointer_gesture_pinch_create_new_resource (MetaWaylandPointer *poin MetaWaylandPointerClient *pointer_client; struct wl_resource *res; - pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client); - g_return_if_fail (pointer_client != NULL); - res = wl_resource_create (client, &zwp_pointer_gesture_pinch_v1_interface, wl_resource_get_version (gestures_resource), id); wl_resource_set_implementation (res, &pointer_gesture_pinch_interface, pointer, meta_wayland_pointer_unbind_pointer_client_resource); - wl_list_insert (&pointer_client->pinch_gesture_resources, - wl_resource_get_link (res)); + + if (pointer) + { + pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client); + g_return_if_fail (pointer_client != NULL); + + wl_list_insert (&pointer_client->pinch_gesture_resources, + wl_resource_get_link (res)); + } } void diff --git a/src/wayland/meta-wayland-pointer-gesture-swipe.c b/src/wayland/meta-wayland-pointer-gesture-swipe.c index dc7abb3c8..924a9ded1 100644 --- a/src/wayland/meta-wayland-pointer-gesture-swipe.c +++ b/src/wayland/meta-wayland-pointer-gesture-swipe.c @@ -166,15 +166,19 @@ meta_wayland_pointer_gesture_swipe_create_new_resource (MetaWaylandPointer *poin MetaWaylandPointerClient *pointer_client; struct wl_resource *res; - pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client); - g_return_if_fail (pointer_client != NULL); - res = wl_resource_create (client, &zwp_pointer_gesture_swipe_v1_interface, wl_resource_get_version (pointer_resource), id); wl_resource_set_implementation (res, &pointer_gesture_swipe_interface, pointer, meta_wayland_pointer_unbind_pointer_client_resource); - wl_list_insert (&pointer_client->swipe_gesture_resources, - wl_resource_get_link (res)); + + if (pointer) + { + pointer_client = meta_wayland_pointer_get_pointer_client (pointer, client); + g_return_if_fail (pointer_client != NULL); + + wl_list_insert (&pointer_client->swipe_gesture_resources, + wl_resource_get_link (res)); + } } void