From: Collin Funk Date: Tue, 14 Oct 2025 03:39:25 +0000 (-0700) Subject: glob tests: Add a test for the glibc bug. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc3bb043e1d8285ff811fc55c4bbfbedf1b3a65b;p=thirdparty%2Fgnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index cee84c0bb2..9ab4c4040a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2025-10-13 Collin Funk + 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: + . + . */ + 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; }