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 2/4] Detect EOL on-the-fly in strstr, strcasestr and memmem.


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


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