[PATCH][BZ #16004] Check overlaps in strcpy.

Ondřej Bílka neleai@seznam.cz
Sat Oct 5 15:12:00 GMT 2013


On Sat, Oct 05, 2013 at 04:53:44PM +0200, Andreas Schwab wrote:
> Ondřej Bílka <neleai@seznam.cz> writes:
> 
> > 	* sysdeps/x86_64/strcpy_chk.S: Optimize implementation and add
> > 	overlap checks.
> 
> Don't lump together independent changes.
> 
These are very dependent. A closest sequence is first improve
performance by compiling following and fixing to register.

char *__chk_fail();
char *strcpy_chk(char *dest, char *src, char *to)
{
  char *t = __stpcpy (dest, src);
  if (t>to)
    return __chk_fail ();
  return dest;
}

Then add overlap checks. 

char *__chk_fail();
char *strcpy_chk(char *dest,char *src,char *to)
{
  char *t = stpcpy (dest, src);
  if (dest>src && src + (t-dest) > dest)
    return __chk_fail ();
  if (dest<src && t > src)
    return __chk_fail ();
  if (t>to)
    return __chk_fail ();
  return dest;
}

As resulting assembly is only superficial to previous one so I 
omitted that step.



More information about the Libc-alpha mailing list