xutil: fix possible overflow

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-08-24 12:03:29 +02:00
parent 62d0d08caf
commit dfe137fab9
1 changed files with 9 additions and 1 deletions

View File

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