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 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.

Cheers,
Carlos.
-- 
Carlos O'Donell
Mentor Graphics / CodeSourcery
carlos_odonell@mentor.com
carlos@codesourcery.com
+1 (613) 963 1026


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