On Cygwin (2.9.0 or 3.6.4), the test with "/*///////sh" fails with n (= initially 10000) >= 8175.
To make it pass, we need to override glob() on this platform. This patch does it. 2025-10-15 Bruno Haible <[email protected]> glob: Fix test failure on Cygwin. * m4/glob.m4 (gl_GLOB): Add a second test case. * doc/posix-functions/glob.texi: Mention Cygwin. diff --git a/doc/posix-functions/glob.texi b/doc/posix-functions/glob.texi index c74f62f967..d3cc89442e 100644 --- a/doc/posix-functions/glob.texi +++ b/doc/posix-functions/glob.texi @@ -26,7 +26,8 @@ can cause the stack to overflow: @c https://sourceware.org/PR30635 @c https://sourceware.org/PR33537 -glibc 2.42. +glibc 2.42, +Cygwin. @end itemize Portability problems not fixed by Gnulib: diff --git a/m4/glob.m4 b/m4/glob.m4 index 6f086f78c2..77b1cc8380 100644 --- a/m4/glob.m4 +++ b/m4/glob.m4 @@ -1,5 +1,5 @@ # glob.m4 -# serial 32 +# serial 33 dnl Copyright (C) 2005-2007, 2009-2025 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -39,23 +39,35 @@ AC_DEFUN([gl_GLOB] and earlier. */ char *p = malloc (10000); glob_t g; - int res = 0; + int result = 0; if (p != NULL) { + /* This test fails on glibc <= 2.42 (stack overflow). */ memset (p, '/', 9999); p[9999] = '\0'; - res = glob (p, 0, NULL, &g); + if (glob (p, 0, NULL, &g) != 0) + result |= 1; + globfree (&g); + /* This test fails on Cygwin 3.6.4 (return value + GLOB_ABORTED). */ + memset (p, '/', 9997); + p[1] = '*'; + strcpy (p + 9997, "sh"); + if (glob (p, 0, NULL, &g) != 0) + result |= 2; globfree (&g); } - return !(res == 0); + return result; }]])], [gl_cv_glob_overflows_stack=no], [gl_cv_glob_overflows_stack=yes], [case "$host_os" in - # Guess yes on glibc systems. - *-gnu* | gnu*) gl_cv_glob_overflows_stack="guessing yes" ;; - # If we don't know, obey --enable-cross-guesses. - *) gl_cv_glob_overflows_stack="$gl_cross_guess_inverted" ;; + # Guess yes on glibc systems. + *-gnu* | gnu*) gl_cv_glob_overflows_stack="guessing yes" ;; + # Guess yes on Cygwin. + cygwin*) gl_cv_glob_overflows_stack="guessing yes" ;; + # If we don't know, obey --enable-cross-guesses. + *) gl_cv_glob_overflows_stack="$gl_cross_guess_inverted" ;; esac ]) ])
