[Xcb-commit] icccm

Peter Harris peterh at kemper.freedesktop.org
Tue Aug 3 07:20:10 PDT 2010


 icccm/icccm.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

New commits:
commit 9b18dc87b29427f6bca492cd279a2b2f74e2638a
Author: Peter Harris <pharris at opentext.com>
Date:   Tue Aug 3 07:48:32 2010 -0400

    Ensure get_wm_class_from_reply returns a valid C-string
    
    Fixes bugzilla #29373
    https://bugs.freedesktop.org/show_bug.cgi?id=29373
    
    Tested-by: Uli Schlachter <psychon at znc.in>
    Signed-off-by: Peter Harris <pharris at opentext.com>

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;


More information about the xcb-commit mailing list