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: [PATCH][BZ #16004] Check overlaps in strcpy.


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.


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