Collin Funk <[email protected]> writes:

> I'll fix those locally.

I pushed that patch with the minor adjustments you mentioned now that my
glibc patch is reviewed and pushed [1][2].

I also added the two test cases to gnulib, that way we can catch any
other platforms that have a bug like this, or regressions.

Collin

[1] 
https://gitweb.git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commit;h=f1a18f6f4cb3bb8ddbc930c4568be9e6ba257b72
[2] 
https://forge.sourceware.org/glibc/glibc-mirror/commit/bb1d27b94a3614c7e48212a04a0b28ec66fb4c49

>From bc3bb043e1d8285ff811fc55c4bbfbedf1b3a65b Mon Sep 17 00:00:00 2001
Message-ID: <bc3bb043e1d8285ff811fc55c4bbfbedf1b3a65b.1760413720.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Mon, 13 Oct 2025 20:39:25 -0700
Subject: [PATCH] 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.
---
 ChangeLog         |  4 ++++
 tests/test-glob.c | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index cee84c0bb2..9ab4c4040a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2025-10-13  Collin Funk  <[email protected]>
 
+	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.
diff --git a/tests/test-glob.c b/tests/test-glob.c
index b064e37b40..140a2b10f5 100644
--- a/tests/test-glob.c
+++ b/tests/test-glob.c
@@ -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;
 }
-- 
2.51.0

Reply via email to