This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 2/4] Detect EOL on-the-fly in strstr, strcasestr and memmem.
- From: Andreas Jaeger <aj at suse dot com>
- To: libc-alpha at sourceware dot org
- Cc: Carlos O'Donell <carlos_odonell at mentor dot com>,Maxim Kuvyrkov <maxim at codesourcery dot com>,"H. J. Lu Lu" <hjl dot tools at gmail dot com>,Carlos O'Donell <carlos at codesourcery dot com>,Eric Blake <eblake at redhat dot com>, Ryan Arnold <rsa at us dot ibm dot com>
- Date: Tue, 09 Oct 2012 09:06:05 +0200
- Subject: Re: [PATCH 2/4] Detect EOL on-the-fly in strstr, strcasestr and memmem.
- References: <2C516CF2-D083-4C1D-AD27-6A31D381D548@codesourcery.com> <6FB629FE-F509-43DA-B99E-89F725D96BA1@codesourcery.com> <507324D7.7090300@mentor.com>
On Monday, October 08, 2012 15:09:11 Carlos O'Donell wrote:
> On 10/8/2012 2:30 PM, Maxim Kuvyrkov wrote:
> >>> Thanks for the testcase, I'll investigate this today.
> >
> > The problem is in initialization phase of matching the needle when
> > length of haystack is about the same as needle. We match the
> > needle from inside out, starting with some point inside the needle
> > (aka needle[suffix]), match the right side first, then the left
> > side. If the haystack is short, then haystack[suffix] may turn out
> > to be beyond the end of haystack, thus causing the bug. Current
> > implementation correctly detects any EOL after haystack[suffix] and
> > the attached patch adds a check for EOL from haystack[0] to
> > haystack[suffix].
> >
> > The actual fix is this hunk:
> >
> > +#if CHECK_AVAILABLE_AFTER
> > + /* We start matching from the SUFFIX'th element, so make sure
> > we + don't hit '\0' before that. */
> > + if (haystack_len < suffix + 1
> > + && !AVAILABLE (haystack, haystack_len, 0, suffix + 1))
> > + return NULL;
> > +#endif
> >
> > ... the rest of the patch cleans up macro definitions (the
> > alternative would be to add yet another AVAILABLE3() macro to use
> > it just once in the above check).
> >
> > Tested on i686-linux-gnu for both -m32 and -m64 multilibs with no
> > regressions.
> >
> > OK to apply?
>
> I'm reviewed this and it looks correct.
>
> OK to checkin as long as you add comments for CHECK_AVAILABLE_AFTER in
> the header str-two-way.h or somewhere else.
>
> I'd like this conditional to be well documented for future
> maintainers.
Could we have this backported to 2.16, please?
Carlos, is that ok?
Andreas
--
Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126