From dfe137fab915dc4c0acf4c3c8662b868591f1b50 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 24 Aug 2009 12:03:29 +0200 Subject: [PATCH] xutil: fix possible overflow Signed-off-by: Julien Danjou --- common/xutil.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/xutil.h b/common/xutil.h index f9e41fdd..bce09e08 100644 --- a/common/xutil.h +++ b/common/xutil.h @@ -40,7 +40,15 @@ xutil_get_text_property_from_reply(xcb_get_property_reply_t *reply) || reply->type == COMPOUND_TEXT) && reply->format == 8 && xcb_get_property_value_length(reply)) - return a_strndup(xcb_get_property_value(reply), xcb_get_property_value_length(reply)); + { + /* We need to copy it that way since the string may not be + * NULL-terminated */ + int len = xcb_get_property_value_length(reply); + char *value = p_new(char, len + 1); + memcpy(value, xcb_get_property_value(reply), len); + value[len] = '\0'; + return value; + } return NULL; }