]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
glob tests: Add a test for the glibc bug.
authorCollin Funk <collin.funk1@gmail.com>
Tue, 14 Oct 2025 03:39:25 +0000 (20:39 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Tue, 14 Oct 2025 03:39:49 +0000 (20:39 -0700)
* tests/test-glob.c (main): Add a test case for all slash characters and
a test case for many slash characters following a wildcard character.

ChangeLog
tests/test-glob.c

index cee84c0bb22cfc760ea67a993617292ad4906e1a..9ab4c4040abec8a3b161bca49480be0c6a96cb38 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2025-10-13  Collin Funk  <collin.funk1@gmail.com>
 
+       glob tests: Add a test for the glibc bug.
+       * tests/test-glob.c (main): Add a test case for all slash characters and
+       a test case for many slash characters following a wildcard character.
+
        glob: Prevent a stack overflow with many slashes.
        * lib/glob.c (__glob): Strip trailing slashes before making the
        recursive call.
index b064e37b406aed1b2df972d00e448e2eff697354..140a2b10f5ac05f4cb703253b1b2616a3d6c1d57 100644 (file)
@@ -95,5 +95,29 @@ main ()
       globfree (&g);
     }
 
+  /* Check for a glibc 2.42 bug where recursive calls cause the stack to
+     overflow.  Test cases based on the following:
+     <https://sourceware.org/PR30635>.
+     <https://sourceware.org/PR33537>.  */
+  char *pattern = malloc (10000);
+  if (pattern != NULL)
+    {
+      /* "/////////".  */
+      memset (pattern, '/', 9999);
+      pattern[9999] = '\0';
+      res = glob (pattern, 0, NULL, &g);
+      ASSERT (res == 0);
+      globfree (&g);
+
+      /* "/*/////sh".  */
+      pattern[1] = '*';
+      pattern[9997] = 's';
+      pattern[9998] = 'h';
+      res = glob (pattern, 0, NULL, &g);
+      ASSERT (res == 0);
+      globfree (&g);
+      free (pattern);
+    }
+
   return test_exit_status;
 }