This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PING][PATCH] Improve str(n)cat_chk performance.



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]