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
This commit is contained in:
Sebastian Keller 2016-01-10 04:15:09 +01:00 committed by Rui Matos
parent 5e57af6286
commit a7a376ae1f

View File

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