Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 9 Apr 2014 15:54:03 +0300
From: Timo Teras <timo.teras@....fi>
To: u-igbb@...ey.se
Cc: musl@...ts.openwall.com
Subject: Re: memmem() - is it correct?

On Wed, 9 Apr 2014 15:51:16 +0300
Timo Teras <timo.teras@....fi> wrote:

> On Wed, 9 Apr 2014 12:49:25 +0200
> u-igbb@...ey.se wrote:
> 
> > On Wed, Apr 09, 2014 at 01:19:03PM +0300, Timo Teras wrote:
> > > >   const char *haystack = "abcde";
> > > >   return(!memmem(haystack, 4, "cde", 3));
> > 
> > > > returns 1 (as I would expect it to) if linked against uclibc
> > > > returns 0                           if linked against musl
> > > > (on ia32)
> > 
> > I guess you misinterpreted the test code, there is a '!' which
> > transforms a returned pointer (success) to 0 exit status in main()
> > and vice versa.
> 
> Right. Should have read it more carefully.  Yes, looks like musl bug.
> 
> Perhaps something like the following is in place:

Wrong patch version. Should be as simple as:

diff --git a/src/string/memmem.c b/src/string/memmem.c
index 5211d75..1173020 100644
--- a/src/string/memmem.c
+++ b/src/string/memmem.c
@@ -139,6 +139,7 @@ void *memmem(const void *h0, size_t k, const void
*n0, size_t l) /* Use faster algorithms for short needles */
 	h = memchr(h0, *n, k);
 	if (!h || l==1) return (void *)h;
+	k -= h - (const unsigned char*)h0;
 	if (l==2) return twobyte_memmem(h, k, n);
 	if (l==3) return threebyte_memmem(h, k, n);
 	if (l==4) return fourbyte_memmem(h, k, n);

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.