From 134e159bc90a8f45d546d01063e24c60260921c6 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 1 May 2019 20:39:00 +0000 Subject: [PATCH] gdk: add a sanity check for events Before delivering events to GTK, make sure they're sane. For now, this means making sure the surface and device are from the same display. --- gdk/gdkevents.c | 39 ++++++++++++++++++++++++++++++++++++--- gdk/gdkeventsprivate.h | 2 ++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index d9e9af6eef..8d31e55fda 100644 --- a/gdk/gdkevents.c +++ b/gdk/gdkevents.c @@ -146,15 +146,48 @@ gdk_event_class_init (GdkEventClass *klass) g_object_class_install_properties (object_class, N_PROPS, event_props); } -void -_gdk_event_emit (GdkEvent *event) +gboolean +check_event_sanity (GdkEvent *event) { + GdkDisplay *display; + GdkSurface *surface; + GdkDevice *device; + + display = gdk_event_get_display (event); + surface = gdk_event_get_surface (event); + device = gdk_event_get_device (event); + if (gdk_event_get_event_type (event) == GDK_NOTHING) { g_warning ("Ignoring GDK_NOTHING events; they're good for nothing"); - return; + return FALSE; } + if (surface && display != gdk_surface_get_display (surface)) + { + char *type = g_enum_to_string (GDK_TYPE_EVENT_TYPE, event->any.type); + g_warning ("Event of type %s with mismatched surface display", type); + g_free (type); + return FALSE; + } + + if (device && display != gdk_device_get_display (device)) + { + char *type = g_enum_to_string (GDK_TYPE_EVENT_TYPE, event->any.type); + g_warning ("Event of type %s with mismatched device display", type); + g_free (type); + return FALSE; + } + + return TRUE; +} + +void +_gdk_event_emit (GdkEvent *event) +{ + if (!check_event_sanity (event)) + return; + if (gdk_drag_handle_source_event (event)) return; diff --git a/gdk/gdkeventsprivate.h b/gdk/gdkeventsprivate.h index 2db43d9a82..eefc1f4622 100644 --- a/gdk/gdkeventsprivate.h +++ b/gdk/gdkeventsprivate.h @@ -645,5 +645,7 @@ void gdk_event_set_related_target (GdkEvent *event, GObject *user_data); GObject * gdk_event_get_related_target (const GdkEvent *event); +gboolean check_event_sanity (GdkEvent *event); + #endif /* __GDK_EVENTS_PRIVATE_H__ */