Merge pull request #1429 from emersion/primary-serial-validation

gtk-primary-selection: basic serial validation
This commit is contained in:
Drew DeVault 2018-12-09 10:44:50 -05:00 committed by GitHub
commit 25b150352c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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;

View File

@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -97,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(
@ -137,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) {
@ -199,10 +204,18 @@ 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;
}
// 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);
}