This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PING][PATCH] Improve str(n)cat_chk performance.
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-alpha at sourceware dot org
- Date: Wed, 26 Aug 2015 17:52:39 -0300
- Subject: Re: [PING][PATCH] Improve str(n)cat_chk performance.
- Authentication-results: sourceware.org; auth=none
- References: <20150820073517 dot GA6785 at domone> <20150826164303 dot GA27006 at domone>
On 26-08-2015 13:43, OndÅej BÃlka wrote:
> ping
>> - while (c != '\0');
>> + size_t len = strlen (dest);
>> + size_t srclen = strlen (src);
>>
>> + if (__glibc_unlikely (len + srclen + 1 > destlen))
>> + __chk_fail ();
Couldn't this test potentially wrap over the unsigned operation? I think
we should add an extra test to avoid this:
/* Check if the unsigned operation do not wrap. */
if (__glibc_unlikely(SIZE_MAX - (srclen + 1) < len))
__chk_fail ();
if (__glibc_unlikely(len + srclen + 1 > destlen))
__chk_fail ();
Same applies for strncat_chk.
>> + if (__glibc_unlikely (len + srclen + 1 > destlen))
>> + __chk_fail ();
>>
>> - return s;
>> + dest[len + srclen] = 0;
>> + memcpy (dest + len, src, srclen);
>> + return dest;
>> }
>