From patchwork Thu Jun 8 21:13:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 103407 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp2632301qgd; Thu, 8 Jun 2017 14:14:22 -0700 (PDT) X-Received: by 10.84.218.72 with SMTP id f8mr37895500plm.33.1496956462473; Thu, 08 Jun 2017 14:14:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496956462; cv=none; d=google.com; s=arc-20160816; b=ebE6CgNMQVo9U20a4BSeo/FhHFYRmx1anSNDNiKQmvTYlmYdS3ZpzQppN9U53TideD LiVlsXhSwW7tLLL5EG2kV3ike1CvUBk9FfGXrtJvsjUfqROacnMGj9GDK+DxjmGZ7bK8 /em9YTZJaVPGKPAhq4J/Wc3yaYd0sHu5gEvj38fUhKMAOC0XL1amASvwIDInrd7tt+5i ABTl9jET+dymF0ULTl89WpEzZp4fGAHaQVZoMPl/RBhRS1r4JMCjXhpD+kqyu34AQBr1 5gT2EdbmQqtbQzmWxLBm5pqPm10sbc2SnnsO2cCpun8C58sbZ974ghQ+RznLZ2qPDodi FNbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=NpQ2B8hzONIsIoS72b6tUIELSb18Bnfi+A7bfVBO9zI=; b=l3uF3JZOFRPy9+0uwMcu+hBrbIeKgNvrUk8hBKQZCh5XitAyhe9qM5DOLNKScX5oTu HAwrVrBH+BTcp5ZSx8s+C8q7+Z3Va85V4U4s4x9Eujqb10gvaZxJS52tiLJOQjJOS4ps 9cVQZWQSkJqwy0Vaj8APHLc06oKjtD0ATwEuRcC7CaCoIrBnBh5c+hiHAvlWSISYFaUi NUiFLdase6UQ9xrdwef40+KRHPVBolVkHoBhcJC2bKvbG0n4hQTtC0oEwTYoWySLBxbt QHWtgW3Vqu03s9hBA0ejG9I6ep4ViiSoQ+qwxdOPVSiPJrLPocfIQNPlycTyfHE7kNGG ve+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-80201-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-80201-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id s80si5287979pfi.388.2017.06.08.14.14.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jun 2017 14:14:22 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-80201-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-80201-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-80201-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=oDqTh+rz+ZrNbN5CuCYGqdbvu60OhV7 tABWyCGkDwWCqxN39sbidVODChZ8MiecL/kqGmsxfQrnjchQBuU5kBW+coem5mma 7Kc0a7armimfzQkHan7Kt7hmRPxFJzNXIjN412keFUMFRps+qyRto0gXJ+XMNxAZ lsdCr6X7rtpM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=YPTaOs3zAmH1fPD5ZbD/cDtDMEM=; b=BLB2C l0yOOPc3KF1/p3PH87K8r+rk49JmxT+NeFFmKGn2bE+eo7Z8ypTlHuKQeYJ/ZzG+ g5nu4ekYif5pmHAEsGpzcgBpdW5kBbT/ScnVkSdFJHSchGHwLBPKmIJzu6B8l3E8 BBEAVpyET8TZHR0xXDqXpNlJ27se8J1pL0AYvY= Received: (qmail 37783 invoked by alias); 8 Jun 2017 21:13:50 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 37677 invoked by uid 89); 8 Jun 2017 21:13:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=st64, UD:st, sk:danglin X-HELO: mail-qt0-f181.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=NpQ2B8hzONIsIoS72b6tUIELSb18Bnfi+A7bfVBO9zI=; b=JBV67lX+o+yZ4fpr6Po/HbLgn95Ka8CUo9JYd7hLRAcV467gX76Luwjw6Qa3Iu+XI+ jV/BAU5SZI8k0bVtXt5TTWpX8Br0oXpPGFZ/bi6TmS3RWambJqJlZkUNbxhy3iBGrsVU dkJRvjZExoKK64rNLQXQpFinPAnRf6BnA7V74FckP+wjxtb+fZF37McP1MFTKgneJS+y kubajF+pir1TxjcZ0M6nvDXwk5/tB5frg9a4wosSffxBvKIvxB0c9BLd7jFqOabrqGuZ TYV+UL5lmJn4tHyKml5uJafYmv0r+9+2zUETzSoVVnyy5W34yS/WSCl1poGA45WtG0Ny VaqQ== X-Gm-Message-State: AKS2vOz8l1GyvlUMGm77EtPDcSlDYcCQraeiM78h1OrR0O/g6c0dZkoy c0Kxg82rEazEy+NdotF3mg== X-Received: by 10.55.66.20 with SMTP id p20mr6876605qka.29.1496956427155; Thu, 08 Jun 2017 14:13:47 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 02/17] posix: Allow glob to match dangling symlinks [BZ #866] Date: Thu, 8 Jun 2017 18:13:16 -0300 Message-Id: <1496956411-25594-3-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1496956411-25594-1-git-send-email-adhemerval.zanella@linaro.org> References: <1496956411-25594-1-git-send-email-adhemerval.zanella@linaro.org> This patch makes glob match dangling symlinks. Compared to other glob implementation (*BSD, bash, musl, and other shells as well), GLIBC seems the be the only one that does not match dangling symlinks. As for comment #5 in BZ #866, POSIX does not have any strict specification for dangling symlinks match and it is reasonable that trying to glob everything in a path should return all types of files (such as for a 'rm *'). Also, comment #7 shows even more example where GLIBC current behavior is unexepected. I avoided adding another GNU specific flag to set this behavior and instead make it the default. Although this change the semanthic from previous implementation, I think adding another compat symbol to be really unecessary as from aforementioned reasons (current behavior not defined in any standard, general idea of different implementation is to list dangling symbols). Checked on x86_64-linux-gnu. * posix/Makefile (tests): Add tst-glob_symlinks and remove tst-glob3. * posix/bug-glob1.c: Remove file. * posix/glob.c (glob): Match dangling symlinks. (link_exists2_p): Remove function. (link_exists_p): Likewise. * posix/tst-glob_symlinks.c: New file. * sysdeps/gnu/glob64.c (__stat): Redefine to __lstat. * sysdeps/unix/sysv/linux/i386/glob64.c (__stat): Likewise. --- posix/Makefile | 5 +- posix/bug-glob1.c | 88 ---------------------- posix/glob.c | 122 ++++++++----------------------- posix/tst-glob_symlinks.c | 133 ++++++++++++++++++++++++++++++++++ sysdeps/gnu/glob64.c | 4 +- sysdeps/unix/sysv/linux/i386/glob64.c | 4 +- 6 files changed, 171 insertions(+), 185 deletions(-) delete mode 100644 posix/bug-glob1.c create mode 100644 posix/tst-glob_symlinks.c -- 2.7.4 diff --git a/posix/Makefile b/posix/Makefile index 52b022c..2c0c9f9 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -69,7 +69,7 @@ tests := test-errno tstgetopt testfnm runtests runptests \ tst-mmap tst-mmap-offset tst-getaddrinfo tst-truncate \ tst-truncate64 tst-fork tst-fnmatch tst-regexloc tst-dir \ tst-chmod bug-regex1 bug-regex2 bug-regex3 bug-regex4 \ - tst-gnuglob tst-regex bug-regex6 bug-regex7 \ + tst-gnuglob tst-glob_symlinks tst-regex bug-regex6 bug-regex7 \ bug-regex8 bug-regex9 bug-regex10 bug-regex11 bug-regex12 \ bug-regex13 bug-regex14 bug-regex15 bug-regex16 \ bug-regex17 bug-regex18 bug-regex19 \ @@ -79,7 +79,7 @@ tests := test-errno tstgetopt testfnm runtests runptests \ tst-nice tst-nanosleep tst-regex2 \ transbug tst-rxspencer tst-pcre tst-boost \ bug-ga1 tst-vfork1 tst-vfork2 tst-vfork3 tst-waitid \ - tst-getaddrinfo2 bug-glob1 bug-glob2 bug-glob3 tst-sysconf \ + tst-getaddrinfo2 bug-glob2 bug-glob3 tst-sysconf \ tst-execvp1 tst-execvp2 tst-execlp1 tst-execlp2 \ tst-execv1 tst-execv2 tst-execl1 tst-execl2 \ tst-execve1 tst-execve2 tst-execle1 tst-execle2 \ @@ -249,7 +249,6 @@ tst-rxspencer-ARGS = --utf8 rxspencer/tests tst-rxspencer-no-utf8-ARGS = rxspencer/tests tst-pcre-ARGS = PCRE.tests tst-boost-ARGS = BOOST.tests -bug-glob1-ARGS = "$(objpfx)" tst-execvp3-ARGS = --test-dir=$(objpfx) testcases.h: TESTS TESTS2C.sed diff --git a/posix/bug-glob1.c b/posix/bug-glob1.c deleted file mode 100644 index 05c2da7..0000000 --- a/posix/bug-glob1.c +++ /dev/null @@ -1,88 +0,0 @@ -/* Test case for globbing dangling symlink. By Ulrich Drepper. */ -#include -#include -#include -#include -#include -#include -#include - - -static void prepare (int argc, char *argv[]); -#define PREPARE prepare -static int do_test (void); -#define TEST_FUNCTION do_test () - -#include "../test-skeleton.c" - - -static char *fname; - -static void -prepare (int argc, char *argv[]) -{ - if (argc < 2) - error (EXIT_FAILURE, 0, "missing argument"); - - size_t len = strlen (argv[1]); - static const char ext[] = "globXXXXXX"; - fname = malloc (len + sizeof (ext)); - if (fname == NULL) - error (EXIT_FAILURE, errno, "cannot create temp file"); - again: - strcpy (stpcpy (fname, argv[1]), ext); - fname = mktemp (fname); - if (fname == NULL || *fname == '\0') - error (EXIT_FAILURE, errno, "cannot create temp file name"); - if (symlink ("bug-glob1-does-not-exist", fname) != 0) - { - if (errno == EEXIST) - goto again; - - error (EXIT_FAILURE, errno, "cannot create symlink"); - } - add_temp_file (fname); -} - - -static int -do_test (void) -{ - glob_t gl; - int retval = 0; - int e; - - e = glob (fname, 0, NULL, &gl); - if (e == 0) - { - printf ("glob(\"%s\") succeeded\n", fname); - retval = 1; - } - globfree (&gl); - - size_t fnamelen = strlen (fname); - char buf[fnamelen + 2]; - - strcpy (buf, fname); - buf[fnamelen - 1] = '?'; - e = glob (buf, 0, NULL, &gl); - if (e == 0) - { - printf ("glob(\"%s\") succeeded\n", buf); - retval = 1; - } - globfree (&gl); - - strcpy (buf, fname); - buf[fnamelen] = '*'; - buf[fnamelen + 1] = '\0'; - e = glob (buf, 0, NULL, &gl); - if (e == 0) - { - printf ("glob(\"%s\") succeeded\n", buf); - retval = 1; - } - globfree (&gl); - - return retval; -} diff --git a/posix/glob.c b/posix/glob.c index 3c6b033..250bff1 100644 --- a/posix/glob.c +++ b/posix/glob.c @@ -71,8 +71,8 @@ # define readdir(str) __readdir64 (str) # define getpwnam_r(name, bufp, buf, len, res) \ __getpwnam_r (name, bufp, buf, len, res) -# ifndef __stat64 -# define __stat64(fname, buf) __xstat64 (_STAT_VER, fname, buf) +# ifndef __lstat64 +# define __lstat64(fname, buf) __lxstat64 (_STAT_VER, fname, buf) # endif # define struct_stat64 struct stat64 #else /* !_LIBC */ @@ -1049,9 +1049,9 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), /* Return the directory if we don't check for error or if it exists. */ if ((flags & GLOB_NOCHECK) || (((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) - ? ((*pglob->gl_stat) (dirname, &st) == 0 + ? ((*pglob->gl_lstat) (dirname, &st) == 0 && S_ISDIR (st.st_mode)) - : (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode))))) + : (__lstat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode))))) { size_t newcount = pglob->gl_pathc + pglob->gl_offs; char **new_gl_pathv; @@ -1318,10 +1318,10 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), for (i = oldcount; i < pglob->gl_pathc + pglob->gl_offs; ++i) if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) - ? ((*pglob->gl_stat) (pglob->gl_pathv[i], &st) == 0 - && S_ISDIR (st.st_mode)) - : (__stat64 (pglob->gl_pathv[i], &st64) == 0 - && S_ISDIR (st64.st_mode)))) + ? ((*pglob->gl_lstat) (pglob->gl_pathv[i], &st) == 0 + && (S_ISDIR (st.st_mode) || S_ISLNK (st.st_mode))) + : (__lstat64 (pglob->gl_pathv[i], &st64) == 0 + && (S_ISDIR (st64.st_mode) || S_ISLNK (st64.st_mode))))) { size_t len = strlen (pglob->gl_pathv[i]) + 2; char *new = realloc (pglob->gl_pathv[i], len); @@ -1500,54 +1500,6 @@ weak_alias (__glob_pattern_p, glob_pattern_p) # endif #endif - -/* We put this in a separate function mainly to allow the memory - allocated with alloca to be recycled. */ -static int -__attribute_noinline__ -link_exists2_p (const char *dir, size_t dirlen, const char *fname, - glob_t *pglob -# if !defined _LIBC && !HAVE_FSTATAT - , int flags -# endif - ) -{ - size_t fnamelen = strlen (fname); - char *fullname = __alloca (dirlen + 1 + fnamelen + 1); - struct stat st; - - mempcpy (mempcpy (mempcpy (fullname, dir, dirlen), "/", 1), - fname, fnamelen + 1); - -# if !defined _LIBC && !HAVE_FSTATAT - if (__builtin_expect ((flags & GLOB_ALTDIRFUNC) == 0, 1)) - { - struct_stat64 st64; - return __stat64 (fullname, &st64) == 0; - } -# endif - return (*pglob->gl_stat) (fullname, &st) == 0; -} - -/* Return true if DIR/FNAME exists. */ -static int -link_exists_p (int dfd, const char *dir, size_t dirlen, const char *fname, - glob_t *pglob, int flags) -{ -# if defined _LIBC || HAVE_FSTATAT - if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) - return link_exists2_p (dir, dirlen, fname, pglob); - else - { - /* dfd cannot be -1 here, because dirfd never returns -1 on - glibc, or on hosts that have fstatat. */ - struct_stat64 st64; - return __fxstatat64 (_STAT_VER, dfd, fname, &st64, 0) == 0; - } -# else - return link_exists2_p (dir, dirlen, fname, pglob, flags); -# endif -} #endif /* !defined GLOB_ONLY_P */ @@ -1619,8 +1571,8 @@ glob_in_dir (const char *pattern, const char *directory, int flags, "/", 1), pattern, patlen + 1); if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) - ? (*pglob->gl_stat) (fullname, &ust.st) - : __stat64 (fullname, &ust.st64)) == 0) + ? (*pglob->gl_lstat) (fullname, &ust.st) + : __lstat64 (fullname, &ust.st64)) == 0) /* We found this file to be existing. Now tell the rest of the function to copy this name into the result. */ flags |= GLOB_NOCHECK; @@ -1642,8 +1594,6 @@ glob_in_dir (const char *pattern, const char *directory, int flags, } else { - int dfd = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) - ? -1 : dirfd ((DIR *) stream)); int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0) #if defined _AMIGA || defined VMS @@ -1679,38 +1629,30 @@ glob_in_dir (const char *pattern, const char *directory, int flags, if (fnmatch (pattern, d.name, fnm_flags) == 0) { - /* If the file we found is a symlink we have to - make sure the target file exists. */ - if (!readdir_result_might_be_symlink (d) - || link_exists_p (dfd, directory, dirlen, d.name, - pglob, flags)) + if (cur == names->count) { - if (cur == names->count) - { - struct globnames *newnames; - size_t count = names->count * 2; - size_t size = (sizeof (struct globnames) - + ((count - INITIAL_COUNT) - * sizeof (char *))); - if (glob_use_alloca (alloca_used, size)) - newnames = names_alloca - = alloca_account (size, alloca_used); - else if ((newnames = malloc (size)) - == NULL) - goto memory_error; - newnames->count = count; - newnames->next = names; - names = newnames; - cur = 0; - } - names->name[cur] = strdup (d.name); - if (names->name[cur] == NULL) - goto memory_error; - ++cur; - ++nfound; - if (SIZE_MAX - pglob->gl_offs <= nfound) + struct globnames *newnames; + size_t count = names->count * 2; + size_t size = (sizeof (struct globnames) + + ((count - INITIAL_COUNT) + * sizeof (char *))); + if (glob_use_alloca (alloca_used, size)) + newnames = names_alloca + = alloca_account (size, alloca_used); + else if ((newnames = malloc (size)) == NULL) goto memory_error; - } + newnames->count = count; + newnames->next = names; + names = newnames; + cur = 0; + } + names->name[cur] = strdup (d.name); + if (names->name[cur] == NULL) + goto memory_error; + ++cur; + ++nfound; + if (SIZE_MAX - pglob->gl_offs <= nfound) + goto memory_error; } } } diff --git a/posix/tst-glob_symlinks.c b/posix/tst-glob_symlinks.c new file mode 100644 index 0000000..c0f1802 --- /dev/null +++ b/posix/tst-glob_symlinks.c @@ -0,0 +1,133 @@ +/* Test glob symlinks return (BZ #866). + for the filesystem access functions. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static void do_prepare (int argc, char *argv[]); +#define PREPARE do_prepare +static int do_test (void); +#include + +static void +create_link (const char *base, const char *fname, char *linkname, + size_t linknamesize) +{ + int ntries = 0; + while (1) + { + snprintf (linkname, linknamesize, "%s/%s%02d", test_dir, base, + ntries); + if (symlink (fname, linkname) == 0) + break; + if (errno != EEXIST) + FAIL_EXIT1 ("symlink failed: %m"); + if (ntries++ == 10) + FAIL_EXIT1 ("symlink failed with EEXIST too many times"); + } + add_temp_file (linkname); +} + +static char valid_link[PATH_MAX]; +static char dangling_link[PATH_MAX]; +static char dangling_dir[PATH_MAX]; + +static void +do_prepare (int argc, char *argv[]) +{ + char *fname; + + create_temp_file ("tst-glob_symlinks.", &fname); + + /* Create a existing symlink. */ + create_link ("valid-symlink-tst-glob_symlinks", fname, valid_link, + sizeof valid_link); + + /* Create a dangling symlink to a file. */ + int fd = create_temp_file ("dangling-tst-glob_file", &fname); + TEST_VERIFY_EXIT (close (fd) == 0); + /* It throws an warning at process end due 'add_temp_file' trying to + unlink it again. */ + TEST_VERIFY_EXIT (unlink (fname) == 0); + create_link ("dangling-symlink-file-tst-glob", fname, dangling_link, + sizeof dangling_link); + + /* Create a dangling symlink to a directory. */ + char tmpdir[PATH_MAX]; + snprintf (tmpdir, sizeof tmpdir, "%s/dangling-tst-glob_folder.XXXXXX", + test_dir); + TEST_VERIFY_EXIT (mkdtemp (tmpdir) != NULL); + create_link ("dangling-symlink-dir-tst-glob", tmpdir, dangling_dir, + sizeof dangling_dir); + TEST_VERIFY_EXIT (rmdir (tmpdir) == 0); +} + +static int +do_test (void) +{ + char buf[PATH_MAX]; + glob_t gl; + + TEST_VERIFY_EXIT (glob (valid_link, 0, NULL, &gl) == 0); + TEST_VERIFY_EXIT (gl.gl_pathc == 1); + TEST_VERIFY_EXIT (strcmp (gl.gl_pathv[0], valid_link) == 0); + globfree (&gl); + + TEST_VERIFY_EXIT (glob (dangling_link, 0, NULL, &gl) == 0); + TEST_VERIFY_EXIT (gl.gl_pathc == 1); + TEST_VERIFY_EXIT (strcmp (gl.gl_pathv[0], dangling_link) == 0); + globfree (&gl); + + TEST_VERIFY_EXIT (glob (dangling_dir, 0, NULL, &gl) == 0); + TEST_VERIFY_EXIT (gl.gl_pathc == 1); + TEST_VERIFY_EXIT (strcmp (gl.gl_pathv[0], dangling_dir) == 0); + globfree (&gl); + + snprintf (buf, sizeof buf, "%s", dangling_link); + buf[strlen(buf) - 1] = '?'; + TEST_VERIFY_EXIT (glob (buf, 0, NULL, &gl) == 0); + TEST_VERIFY_EXIT (gl.gl_pathc == 1); + TEST_VERIFY_EXIT (strcmp (gl.gl_pathv[0], dangling_link) == 0); + globfree (&gl); + + /* glob should handle dangling symbol as normal file, so ? should + return an empty string. */ + snprintf (buf, sizeof buf, "%s?", dangling_link); + TEST_VERIFY_EXIT (glob (buf, 0, NULL, &gl) != 0); + globfree (&gl); + + snprintf (buf, sizeof buf, "%s*", dangling_link); + TEST_VERIFY_EXIT (glob (buf, 0, NULL, &gl) == 0); + TEST_VERIFY_EXIT (gl.gl_pathc == 1); + TEST_VERIFY_EXIT (strcmp (gl.gl_pathv[0], dangling_link) == 0); + globfree (&gl); + + return 0; +} diff --git a/sysdeps/gnu/glob64.c b/sysdeps/gnu/glob64.c index d1e4e6f..250ff07 100644 --- a/sysdeps/gnu/glob64.c +++ b/sysdeps/gnu/glob64.c @@ -12,8 +12,8 @@ #undef stat #define stat stat64 -#undef __stat -#define __stat(file, buf) __xstat64 (_STAT_VER, file, buf) +#undef __lstat +#define __lstat(file, buf) __lxstat64 (_STAT_VER, file, buf) #define NO_GLOB_PATTERN_P 1 diff --git a/sysdeps/unix/sysv/linux/i386/glob64.c b/sysdeps/unix/sysv/linux/i386/glob64.c index 9c7abd8..2dcbe33 100644 --- a/sysdeps/unix/sysv/linux/i386/glob64.c +++ b/sysdeps/unix/sysv/linux/i386/glob64.c @@ -30,8 +30,8 @@ #undef stat #define stat stat64 -#undef __stat -#define __stat(file, buf) __xstat64 (_STAT_VER, file, buf) +#undef __lstat +#define __lstat(file, buf) __lxstat64 (_STAT_VER, file, buf) #define NO_GLOB_PATTERN_P 1