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

Alan Coopersmith alan.coopersmith at oracle.com
Mon Jun 14 07:53:16 PDT 2010


Vincent Torri wrote:
> 
> 
> 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

That would be more consistent with the other utilities for text properties as
well - this was just the simple fix that didn't change API and allowed xwininfo
to show the same strings as the Xlib version did.

I didn't know how widespread use of this is yet, or how painful/acceptable an
API break would be.   If it is acceptable, then I can work on a patch that
instead adds instance_name_len & class_name_len to the xcb_get_wm_class_reply_t
struct.   (Does there need to be an encoding field as well or are wm_class
properties always in the same encoding?    I don't see a mention of that in
ICCCM, but I see ICCCM claims WM_CLASS are always null-terminated, when I found
they weren't always in practice.)

Since the struct is allocated by the caller, this will cause overflow in
existing binaries - should the library .so version be bumped?  How is API
versioning/incompatibility handled?


-- 
	-Alan Coopersmith-        alan.coopersmith at oracle.com
	 Oracle Solaris Platform Engineering: X Window System



More information about the Xcb mailing list