[PATCH] Check for calloc() failure in add_master()
Alan Coopersmith
alan.coopersmith at oracle.com
Sat Jan 25 10:41:59 PST 2014
On 01/25/14 01:32 AM, walter harms wrote:
>
>
> Am 25.01.2014 08:42, schrieb Alan Coopersmith:
>> Reported-by: Ilja Van Sprundel <ivansprundel at ioactive.com>
>> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
>> ---
>> Xi/xichangehierarchy.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
>> index e2f4b8a..9e36354 100644
>> --- a/Xi/xichangehierarchy.c
>> +++ b/Xi/xichangehierarchy.c
>> @@ -143,6 +143,10 @@ add_master(ClientPtr client, xXIAddMasterInfo * c, int flags[MAXDEVICES])
>> int rc;
>>
>> name = calloc(c->name_len + 1, sizeof(char));
>> + if (name == NULL) {
>> + rc = BadAlloc;
>> + goto unwind;
>> + }
>> strncpy(name, (char *) &c[1], c->name_len);
>>
>> rc = AllocDevicePair(client, name, &ptr, &keybd,
>
>
> can you use strdup() here ?
I was thinking strndup() might work, but that would require checking the
later uses of the memory to ensure that they expect the allocated size to
be the string length, not exactly c->name_len + 1, if the two ever happen
to differ. In any case, I left that as an exercise for someone else to
deal with.
--
-Alan Coopersmith- alan.coopersmith at oracle.com
Oracle Solaris Engineering - http://blogs.oracle.com/alanc
More information about the xorg-devel
mailing list