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

(cherry picked from commit f9326cfa3d)
This commit is contained in:
Olivier Fourdan 2020-02-20 10:25:46 +01:00 committed by Robert Mader
parent c65db40178
commit 2709a4ffb1

View File

@ -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;
@ -2187,11 +2179,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;
}