From 8c573bc7c6b3029f2d3dc5c6fe45bf1078a66485 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 9 Dec 2018 12:38:35 +0100 Subject: [PATCH 1/2] gtk-primary-selection: basic serial validation --- include/wlr/types/wlr_gtk_primary_selection.h | 1 + types/wlr_gtk_primary_selection.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/wlr/types/wlr_gtk_primary_selection.h b/include/wlr/types/wlr_gtk_primary_selection.h index 7cf34201..436a50d2 100644 --- a/include/wlr/types/wlr_gtk_primary_selection.h +++ b/include/wlr/types/wlr_gtk_primary_selection.h @@ -36,6 +36,7 @@ struct wlr_gtk_primary_selection_device { struct wl_list resources; // wl_resource_get_link struct wl_list offers; // wl_resource_get_link + uint32_t selection_serial; struct wl_listener seat_destroy; struct wl_listener seat_focus_change; diff --git a/types/wlr_gtk_primary_selection.c b/types/wlr_gtk_primary_selection.c index 5f349154..ca82b3e7 100644 --- a/types/wlr_gtk_primary_selection.c +++ b/types/wlr_gtk_primary_selection.c @@ -1,5 +1,6 @@ #define _POSIX_C_SOURCE 200809L #include +#include #include #include #include @@ -202,7 +203,14 @@ static void device_handle_set_selection(struct wl_client *client, source = &client_source->source; } - // TODO: serial checking + // TODO: improve serial validation + if (device->seat->primary_selection_source != NULL && + device->selection_serial - serial < UINT32_MAX / 2) { + wlr_log(WLR_DEBUG, "Rejecting set_selection request, invalid serial " + "(%"PRIu32" <= %"PRIu32")", serial, device->selection_serial); + return; + } + device->selection_serial = serial; wlr_seat_set_primary_selection(device->seat, source); } From c2113decb3adf1ba67e26df9d93a442128f6d57d Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 9 Dec 2018 12:42:27 +0100 Subject: [PATCH 2/2] gtk-primary-selection: warn when offering MIME type after set_selection --- types/wlr_gtk_primary_selection.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/wlr_gtk_primary_selection.c b/types/wlr_gtk_primary_selection.c index ca82b3e7..18bc624a 100644 --- a/types/wlr_gtk_primary_selection.c +++ b/types/wlr_gtk_primary_selection.c @@ -98,6 +98,7 @@ static void destroy_offer(struct wl_resource *resource) { struct client_data_source { struct wlr_primary_selection_source source; struct wl_resource *resource; + bool finalized; }; static void client_source_send( @@ -138,6 +139,9 @@ static void source_handle_offer(struct wl_client *client, if (source == NULL) { return; } + if (source->finalized) { + wlr_log(WLR_DEBUG, "Offering additional MIME type after set_selection"); + } char *dup_mime_type = strdup(mime_type); if (dup_mime_type == NULL) { @@ -200,6 +204,7 @@ static void device_handle_set_selection(struct wl_client *client, struct wlr_primary_selection_source *source = NULL; if (client_source != NULL) { + client_source->finalized = true; source = &client_source->source; }