From 5816268c1d5e1a9c952bcc74087511ab0d8bf176 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 6 Dec 2022 15:08:47 +0100 Subject: [PATCH] x11: Push error trap reading X11 selection It is a possibility that this request results in an error, so handle the possible fallout. Part-of: --- src/x11/meta-x11-selection-input-stream.c | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/x11/meta-x11-selection-input-stream.c b/src/x11/meta-x11-selection-input-stream.c index fead3685d..5d5aee5d5 100644 --- a/src/x11/meta-x11-selection-input-stream.c +++ b/src/x11/meta-x11-selection-input-stream.c @@ -341,11 +341,11 @@ XFree_without_return_value (gpointer data) } static GBytes * -get_selection_property (Display *xdisplay, - Window owner, - Atom property, - Atom *ret_type, - gint *ret_format) +get_selection_property (MetaX11Display *x11_display, + Window owner, + Atom property, + Atom *ret_type, + gint *ret_format) { gulong nitems; gulong nbytes; @@ -353,10 +353,18 @@ get_selection_property (Display *xdisplay, gint prop_format; uint8_t *data = NULL; - if (XGetWindowProperty (xdisplay, owner, property, + meta_x11_error_trap_push (x11_display); + + if (XGetWindowProperty (x11_display->xdisplay, owner, property, 0, 0x1FFFFFFF, False, AnyPropertyType, &prop_type, &prop_format, &nitems, &nbytes, &data) != Success) + { + meta_x11_error_trap_pop (x11_display); + goto err; + } + + if (meta_x11_error_trap_pop_with_return (x11_display) != Success) goto err; if (prop_type != None) @@ -426,7 +434,8 @@ meta_x11_selection_input_stream_xevent (MetaX11SelectionInputStream *stream, xevent->xproperty.state != PropertyNewValue) return FALSE; - bytes = get_selection_property (xdisplay, xwindow, xevent->xproperty.atom, + bytes = get_selection_property (priv->x11_display, xwindow, + xevent->xproperty.atom, &type, &format); if (bytes == NULL) @@ -477,7 +486,7 @@ meta_x11_selection_input_stream_xevent (MetaX11SelectionInputStream *stream, } else { - bytes = get_selection_property (xdisplay, xwindow, + bytes = get_selection_property (priv->x11_display, xwindow, xevent->xselection.property, &priv->xtype, &priv->format); priv->type = gdk_x11_get_xatom_name (priv->xtype);