Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
data-device: check if there's a source before sending dnd_finish
Browse files Browse the repository at this point in the history
This could cause a segfault in data_offer_destroy if the offer has version < 3.
  • Loading branch information
emersion authored and ddevault committed Feb 25, 2019
1 parent 4212839 commit d425206
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions types/data_device/wlr_data_offer.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void data_offer_handle_receive(struct wl_client *client,
wlr_data_source_send(offer->source, mime_type, fd);
}

static void data_offer_dnd_finish(struct wlr_data_offer *offer) {
static void data_offer_source_dnd_finish(struct wlr_data_offer *offer) {
struct wlr_data_source *source = offer->source;
if (source->actions < 0) {
return;
Expand Down Expand Up @@ -142,7 +142,7 @@ static void data_offer_handle_finish(struct wl_client *client,
return;
}

data_offer_dnd_finish(offer);
data_offer_source_dnd_finish(offer);
data_offer_destroy(offer);
}

Expand Down Expand Up @@ -190,14 +190,14 @@ void data_offer_destroy(struct wlr_data_offer *offer) {
wl_list_remove(&offer->source_destroy.link);
wl_list_remove(&offer->link);

if (offer->type == WLR_DATA_OFFER_DRAG) {
if (offer->type == WLR_DATA_OFFER_DRAG && offer->source) {
// If the drag destination has version < 3, wl_data_offer.finish
// won't be called, so do this here as a safety net, because
// we still want the version >= 3 drag source to be happy.
if (wl_resource_get_version(offer->resource) <
WL_DATA_OFFER_ACTION_SINCE_VERSION) {
data_offer_dnd_finish(offer);
} else if (offer->source && offer->source->impl->dnd_finish) {
data_offer_source_dnd_finish(offer);
} else if (offer->source->impl->dnd_finish) {
wlr_data_source_destroy(offer->source);
}
}
Expand Down

0 comments on commit d425206

Please sign in to comment.