From b1532f465e05d566f6d160c5ca916a5a12614067 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 5 Oct 2012 19:20:18 +0100 Subject: [PATCH] xlib/shm: Avoid using XSendEvent with old versions of Xorg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Søren Sandmann Pedersen pointed out that all versions of Xorg prior to and including xorg-1.11.0 contained a bug that would cause them to crash if they ever processed an event sent by XSendEvent. This was fixed in commit 2d2dce558d24eeea0eb011ec9ebaa6c5c2273c39 Author: Sam Spilsbury Date: Wed Sep 14 09:58:34 2011 +0800 Remove the SendEvent bit (0x80) before doing range checks on event type. so make sure we do not use XSendEvent prior to that commit, which fortuitously is quite easy as we only do so along the ShmPixmap path. Reported-by: Søren Sandmann Pedersen Signed-off-by: Chris Wilson --- src/cairo-xlib-surface-shm.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/cairo-xlib-surface-shm.c b/src/cairo-xlib-surface-shm.c index 08169f21a..3e6eaf276 100644 --- a/src/cairo-xlib-surface-shm.c +++ b/src/cairo-xlib-surface-shm.c @@ -1121,6 +1121,24 @@ _cairo_xlib_shm_surface_is_idle (cairo_surface_t *surface) return shm->idle > 0; } +#define XORG_VERSION_ENCODE(major,minor,patch,snap) \ + (((major) * 10000000) + ((minor) * 100000) + ((patch) * 1000) + snap) + +static cairo_bool_t +xorg_has_buggy_send_event(Display *dpy) +{ + /* Avoid incurring the wrath fixed by: + * + * commit 2d2dce558d24eeea0eb011ec9ebaa6c5c2273c39 + * Author: Sam Spilsbury + * Date: Wed Sep 14 09:58:34 2011 +0800 + * + * Remove the SendEvent bit (0x80) before doing range checks on event type. + */ + return (strstr (ServerVendor (dpy), "X.Org") != NULL && + VendorRelease (dpy) < XORG_VERSION_ENCODE(1,11,0,1)); +} + void _cairo_xlib_display_init_shm (cairo_xlib_display_t *display) { @@ -1153,6 +1171,9 @@ _cairo_xlib_display_init_shm (cairo_xlib_display_t *display) DefaultVisual (display->display, scr), CWOverrideRedirect, &attr); + if (xorg_has_buggy_send_event(display->display)) + has_pixmap = 0; + shm->has_pixmaps = has_pixmap ? MIN_PIXMAP_SIZE : 0; cairo_list_init (&shm->pool);