This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][BZ #16004] Check overlaps in strcpy.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Andreas Schwab <schwab at linux-m68k dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Sat, 5 Oct 2013 17:12:12 +0200
- Subject: Re: [PATCH][BZ #16004] Check overlaps in strcpy.
- Authentication-results: sourceware.org; auth=none
- References: <20131005135104 dot GA9757 at domone> <871u3z93bb dot fsf at igel dot home>
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.