[Xcb] [PATCH:xcb-util] Make sure wm_class name strings are null-terminated

Vincent Torri vtorri at univ-evry.fr
Sun Jun 13 23:36:31 PDT 2010



On Sun, 13 Jun 2010, Alan Coopersmith wrote:

> Previously it worked unless the string happened to be just the right
> length that there was no padding at the end of the reply.   This fixes
> that case at the cost of always allocating new memory for the strings.
>
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
> icccm/icccm.c |   15 ++++++++++++++-
> 1 files changed, 14 insertions(+), 1 deletions(-)
>
> diff --git a/icccm/icccm.c b/icccm/icccm.c
> index e620bde..868d1b1 100644
> --- a/icccm/icccm.c
> +++ b/icccm/icccm.c
> @@ -359,7 +359,19 @@ xcb_get_wm_class_from_reply(xcb_get_wm_class_reply_t *prop,
>     return 0;
>
>   prop->_reply = reply;
> -  prop->instance_name = (char *) xcb_get_property_value(prop->_reply);
> +
> +  /* Reply will not be null terminated, but since caller won't know the
> +     length we have to copy to a null terminated string.

why not providing the length, like what is done in the protocol ?

Vincent


> +     If both instance and class are provided, there will be a null byte
> +     separating them, otherwise we just point class to the null terminator. */
> +  int reply_length = xcb_get_property_value_length(reply);
> +  char *value = (char *) xcb_get_property_value(prop->_reply);
> +
> +  prop->instance_name = malloc(reply_length + 1);
> +  if (!prop->instance_name)
> +    return 0;
> +  memcpy(prop->instance_name, value, reply_length);
> +  prop->instance_name[reply_length] = '\0';
>
>   int name_len = strlen(prop->instance_name);
>   if(name_len == xcb_get_property_value_length(prop->_reply))
> @@ -385,6 +397,7 @@ xcb_get_wm_class_reply(xcb_connection_t *c, xcb_get_property_cookie_t cookie,
> void
> xcb_get_wm_class_reply_wipe(xcb_get_wm_class_reply_t *prop)
> {
> +  free(prop->instance_name);
>   free(prop->_reply);
> }
>
> -- 
> 1.5.6.5
>
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xcb
>
>


More information about the Xcb mailing list