bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Add test case from a past musl libc bug


From: Bruno Haible
Subject: Add test case from a past musl libc bug
Date: Mon, 27 Mar 2023 15:16:51 +0200

There was a bug in the 'strstr' in musl libc, fixed in 2014. I'm adding
the test case to the test suite here, just in case someone copied the old
musl libc code and is still using it somewhere.


2023-03-27  Bruno Haible  <bruno@clisp.org>

        Add test case from a past musl libc bug.
        * tests/test-strstr.c (main): Add test of periodic needle.
        * tests/test-strcasestr.c (main): Likewise.
        * tests/test-c-strstr.c (main): Likewise.
        * tests/test-c-strcasestr.c (main): Likewise.
        * tests/test-memmem.c (main): Likewise.

diff --git a/tests/test-c-strcasestr.c b/tests/test-c-strcasestr.c
index 818f5a994b..4f0a6c262a 100644
--- a/tests/test-c-strcasestr.c
+++ b/tests/test-c-strcasestr.c
@@ -238,6 +238,14 @@ main ()
     free (haystack);
   }
 
+  /* Test case from Yves Bastide.
+     <https://www.openwall.com/lists/musl/2014/04/18/2>  */
+  {
+    const char input[] = "playing PLAY play PLAY always";
+    const char *result = c_strcasestr (input, "play PLAY play");
+    ASSERT (result == input + 8);
+  }
+
   /* Test long needles.  */
   {
     size_t m = 1024;
diff --git a/tests/test-c-strstr.c b/tests/test-c-strstr.c
index d8f8465b29..30070d70a4 100644
--- a/tests/test-c-strstr.c
+++ b/tests/test-c-strstr.c
@@ -212,6 +212,14 @@ main ()
     free (haystack);
   }
 
+  /* Test case from Yves Bastide.
+     <https://www.openwall.com/lists/musl/2014/04/18/2>  */
+  {
+    const char input[] = "playing play play play always";
+    const char *result = c_strstr (input, "play play play");
+    ASSERT (result == input + 8);
+  }
+
   /* Test long needles.  */
   {
     size_t m = 1024;
diff --git a/tests/test-memmem.c b/tests/test-memmem.c
index 0daf3b07e7..589210f4a2 100644
--- a/tests/test-memmem.c
+++ b/tests/test-memmem.c
@@ -292,6 +292,14 @@ main (int argc, char *argv[])
     free (haystack);
   }
 
+  /* Test case from Yves Bastide.
+     <https://www.openwall.com/lists/musl/2014/04/18/2>  */
+  {
+    const char input[] = "playing play play play always";
+    const char *result = memmem (input, strlen (input), "play play play", 14);
+    ASSERT (result == input + 8);
+  }
+
   /* Test long needles.  */
   {
     size_t m = 1024;
diff --git a/tests/test-strcasestr.c b/tests/test-strcasestr.c
index 192e1569f8..c0f5111b4a 100644
--- a/tests/test-strcasestr.c
+++ b/tests/test-strcasestr.c
@@ -252,6 +252,14 @@ main ()
     free (haystack);
   }
 
+  /* Test case from Yves Bastide.
+     <https://www.openwall.com/lists/musl/2014/04/18/2>  */
+  {
+    const char input[] = "playing PLAY play PLAY always";
+    const char *result = strcasestr (input, "play PLAY play");
+    ASSERT (result == input + 8);
+  }
+
   /* Test long needles.  */
   {
     size_t m = 1024;
diff --git a/tests/test-strstr.c b/tests/test-strstr.c
index b2e00c526c..1ff9953d31 100644
--- a/tests/test-strstr.c
+++ b/tests/test-strstr.c
@@ -275,6 +275,14 @@ main (int argc, char *argv[])
     free (haystack);
   }
 
+  /* Test case from Yves Bastide.
+     <https://www.openwall.com/lists/musl/2014/04/18/2>  */
+  {
+    const char input[] = "playing play play play always";
+    const char *result = strstr (input, "play play play");
+    ASSERT (result == input + 8);
+  }
+
   /* Test long needles.  */
   {
     size_t m = 1024;






reply via email to

[Prev in Thread] Current Thread [Next in Thread]