From 6dc4243e2e56d500c3d602dffa9ccca6ac2040d0 Mon Sep 17 00:00:00 2001 From: Peter Harris Date: Tue, 3 Aug 2010 07:48:32 -0400 Subject: [PATCH] Ensure get_wm_class_from_reply returns a valid C-string --- icccm/icccm.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-) diff --git a/icccm/icccm.c b/icccm/icccm.c index 260a557..b06d683 100644 --- a/icccm/icccm.c +++ b/icccm/icccm.c @@ -337,8 +337,17 @@ xcb_get_wm_class_from_reply(xcb_get_wm_class_reply_t *prop, prop->_reply = reply; prop->instance_name = (char *) xcb_get_property_value(prop->_reply); + int len = xcb_get_property_value_length(prop->_reply); + /* Ensure there's a C end-of-string at the end of the property. + Truncate the property if necessary (the spec says there's already + a 0 in the last position, so this only hurts invalid props). */ + if(len < reply->length * 4) + prop->instance_name[len] = 0; + else + prop->instance_name[len-1] = 0; + int name_len = strlen(prop->instance_name); - if(name_len == xcb_get_property_value_length(prop->_reply)) + if(name_len == len) name_len--; prop->class_name = prop->instance_name + name_len + 1; -- 1.7.2.1