[klibc] memmem broken?

Olaf Hering olh at suse.de
Wed Feb 16 12:55:04 PST 2005


 On Wed, Feb 16, Kay Sievers wrote:

> We have a bad bug in udev if compiled with klibc. I seems that the needle
> string can't have a strlen of 1. This test case illustrates it:

--- klibc/memmem.c
+++ klibc/memmem.c
@@ -18,9 +18,10 @@ void *memmem(const void *haystack, size_
 
   size_t j, k, l;
 
-  if ( m > n )
+  if (m > n || !m || !n)
     return NULL;
 
+  if (1 != m) {
   if ( x[0] == x[1] ) {
     k = 2;
     l = 1;
@@ -39,6 +40,12 @@ void *memmem(const void *haystack, size_
       j += l;
     }
   }
+	} else
+		do {
+			if (*y == *x)
+				return (void *)y;
+			y++;
+		} while (--n);
 
   return NULL;
 }



More information about the klibc mailing list