[mutter] wayland/data-device: Fix crash with offer from X11 client



commit f9326cfa3d5f0fd9f63f561d6dfbb92a8f6fb34a
Author: Olivier Fourdan <ofourdan redhat com>
Date:   Thu Feb 20 10:25:46 2020 +0100

    wayland/data-device: Fix crash with offer from X11 client
    
    If a data offer comes from an X11 client, the Wayland resource would be
    NULL, causing a crash in `data_offer_choose_action()` trying to get the
    resource version.
    
    So instead of doing the version check in `data_offer_choose_action()`,
    do it early when creating the data source.
    
    Closes: https://gitlab.gnome.org/GNOME/mutter/issues/1057
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/1073

 src/wayland/meta-wayland-data-device.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/src/wayland/meta-wayland-data-device.c b/src/wayland/meta-wayland-data-device.c
index 8aaf698e8..3a7cfd4dc 100644
--- a/src/wayland/meta-wayland-data-device.c
+++ b/src/wayland/meta-wayland-data-device.c
@@ -143,16 +143,8 @@ data_offer_choose_action (MetaWaylandDataOffer *offer)
       WL_DATA_OFFER_ACTION_SINCE_VERSION)
     return WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
 
-  if (wl_resource_get_version (meta_wayland_data_source_get_resource (source)) <
-      WL_DATA_SOURCE_ACTION_SINCE_VERSION)
-    {
-      actions = user_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
-    }
-  else
-    {
-      actions = meta_wayland_data_source_get_actions (source);
-      user_action = meta_wayland_data_source_get_user_action (source);
-    }
+  actions = meta_wayland_data_source_get_actions (source);
+  user_action = meta_wayland_data_source_get_user_action (source);
 
   available_actions = actions & offer->dnd_actions;
 
@@ -2200,11 +2192,19 @@ meta_wayland_data_source_new (struct wl_resource *resource)
 {
   MetaWaylandDataSource *source =
    g_object_new (META_TYPE_WAYLAND_DATA_SOURCE, NULL);
+  MetaWaylandDataSourcePrivate *priv =
+    meta_wayland_data_source_get_instance_private (source);
 
   meta_wayland_data_source_set_resource (source, resource);
   wl_resource_set_implementation (resource, &data_source_interface,
                                   source, destroy_data_source);
 
+  if (wl_resource_get_version (resource) < WL_DATA_SOURCE_ACTION_SINCE_VERSION)
+    {
+      priv->dnd_actions = priv->user_dnd_action =
+        WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
+    }
+
   return source;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]