]> Savannah Git Hosting - gnulib.git/commitdiff
glob: test for glibc bug 25659
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 23 Mar 2022 17:22:51 +0000 (10:22 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 23 Mar 2022 17:24:44 +0000 (10:24 -0700)
https://sourceware.org/bugzilla/show_bug.cgi?id=25659
* m4/glob.m4 (gl_GLOB): Replace glob if it has bug 25659.
* tests/test-glob.c (main): Test for glibc bug 25659.

ChangeLog
m4/glob.m4
tests/test-glob.c

index a0d351916254d6a422a91727507e2a7f3d15c1ce..7ea4f7797b30fdde564b4da540c6d4fe161aea02 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2022-03-23  Paul Eggert  <eggert@cs.ucla.edu>
 
+       glob: test for glibc bug 25659
+       https://sourceware.org/bugzilla/show_bug.cgi?id=25659
+       * m4/glob.m4 (gl_GLOB): Replace glob if it has bug 25659.
+       * tests/test-glob.c (main): Test for glibc bug 25659.
+
        glob: fix symlink and // issues; improve speed
        * lib/glob.c: Include fcntl.h.
        (dirfd) [_LIBC]: New macro.
index 0d1426389b2121e30259806f75281186ba8e583d..cf5f93930c1fb8b529561abab9a81ad49bf5240c 100644 (file)
@@ -1,4 +1,4 @@
-# glob.m4 serial 24
+# glob.m4 serial 25
 dnl Copyright (C) 2005-2007, 2009-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -66,6 +66,45 @@ char a[_GNU_GLOB_INTERFACE_VERSION == 1 || _GNU_GLOB_INTERFACE_VERSION == 2 ? 1
       esac
     fi
 
+    if test $REPLACE_GLOB = 0; then
+      AC_CACHE_CHECK([whether glob NOTDIR*/ omits symlink to nondir],
+                     [gl_cv_glob_omit_nondir_symlinks],
+        [if test $cross_compiling != yes; then
+           if ln -s conf-file conf$$-globtest 2>/dev/null && touch conf-file
+           then
+             gl_cv_glob_omit_nondir_symlinks=maybe
+           else
+             # If we can't make a symlink, then we cannot test this issue.  Be
+             # pessimistic about this.
+             gl_cv_glob_omit_nondir_symlinks=no
+           fi
+           if test $gl_cv_glob_omit_nondir_symlinks = maybe; then
+             AC_RUN_IFELSE(
+               [AC_LANG_PROGRAM(
+                  [[#include <stddef.h>
+                    #include <glob.h>]],
+                  [[glob_t found;
+                    if (glob ("conf*-globtest/", 0, NULL, &found) != GLOB_NOMATCH)
+                      return 1;
+                    globfree (&found);
+                  ]])],
+               [gl_cv_glob_omit_nondir_symlinks=yes],
+               [gl_cv_glob_omit_nondir_symlinks=no],
+               [dnl We don't get here.
+                :
+               ])
+           fi
+           rm -f conf$$-globtest
+         else
+           gl_cv_glob_omit_nondir_symlinks="$gl_cross_guess_normal"
+         fi
+        ])
+      case "$gl_cv_glob_omit_nondir_symlinks" in
+        *yes) ;;
+        *) REPLACE_GLOB=1 ;;
+      esac
+    fi
+
   fi
 
   if test $ac_cv_func_glob_pattern_p = no; then
index 2709080bc788f7fbd42a41f70974033416d8a315..568acf14b76685465ac06cc7ed778bf4c6b83e86 100644 (file)
@@ -72,7 +72,9 @@ main ()
   globfree (&g);
 
   if ((symlink (GL_NO_SUCH_FILE, BASE "globlink1") == 0 || errno == EEXIST)
-      && (symlink (".", BASE "globlink2") == 0 || errno == EEXIST))
+      && (symlink (".", BASE "globlink2") == 0 || errno == EEXIST)
+      && (symlink (BASE "globfile", BASE "globlink3") == 0 || errno == EEXIST)
+      && close (creat (BASE "globfile", 0666)) == 0)
     {
       res = glob (BASE "globlink[12]", 0, NULL, &g);
       ASSERT (res == 0 && g.gl_pathc == 2);
@@ -80,6 +82,11 @@ main ()
       ASSERT (strcmp (g.gl_pathv[1], BASE "globlink2") == 0);
       globfree (&g);
 
+      res = glob (BASE "globlink[123]/", 0, NULL, &g);
+      ASSERT (res == 0 && g.gl_pathc == 1);
+      ASSERT (strcmp (g.gl_pathv[0], BASE "globlink2/") == 0);
+      globfree (&g);
+
       res = glob (BASE "globlink[12]", GLOB_MARK, NULL, &g);
       ASSERT (res == 0 && g.gl_pathc == 2);
       ASSERT (strcmp (g.gl_pathv[0], BASE "globlink1") == 0);