From a7a376ae1fafb7c9da50d9fe51fc08b0ec13f55e Mon Sep 17 00:00:00 2001 From: Sebastian Keller Date: Sun, 10 Jan 2016 04:15:09 +0100 Subject: [PATCH] xprops: Null-terminate property reply values Some of the mutter code using these properties expects them to be null-terminated whereas xcb does not use null-terminated strings: http://xcb.freedesktop.org/XcbRationale/ This was in some cases resulting in the WM_CLASS property containing garbage data which broke application matching, caused the hot-corner and window-switcher to stop working, or was exposed as text in the UI. https://bugzilla.gnome.org/show_bug.cgi?id=759658 --- src/x11/xprops.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/x11/xprops.c b/src/x11/xprops.c index be3882455..e3bd931f0 100644 --- a/src/x11/xprops.c +++ b/src/x11/xprops.c @@ -194,6 +194,7 @@ async_get_property_finish (xcb_connection_t *xcb_conn, { xcb_get_property_reply_t *reply; xcb_generic_error_t *error; + int length; reply = xcb_get_property_reply (xcb_conn, cookie, &error); if (error) @@ -209,8 +210,15 @@ async_get_property_finish (xcb_connection_t *xcb_conn, results->prop = NULL; if (results->type != None) - results->prop = g_memdup (xcb_get_property_value (reply), - xcb_get_property_value_length (reply)); + { + length = xcb_get_property_value_length (reply); + /* Leave room for a trailing '\0' since xcb doesn't return null-terminated + * strings + */ + results->prop = g_malloc (length + 1); + memcpy (results->prop, xcb_get_property_value (reply), length); + results->prop[length] = '\0'; + } free (reply); return (results->prop != NULL);