This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PING][PATCH 2/1][BZ #866] glob() should match dangling symlinks.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: glibc at tomlee dot co, libc-alpha at sourceware dot org
- Date: Thu, 2 Jan 2014 21:26:48 +0100
- Subject: [PING][PATCH 2/1][BZ #866] glob() should match dangling symlinks.
- Authentication-results: sourceware.org; auth=none
- References: <20131003075937 dot GA22576 at domone dot podge> <20131012082529 dot GA12308 at domone dot podge> <52601A27 dot 7080507 at redhat dot com> <20131204212128 dot GA10605 at domone dot podge>
ping
On Wed, Dec 04, 2013 at 10:21:28PM +0100, OndÅej BÃlka wrote:
> On Thu, Oct 17, 2013 at 01:11:03PM -0400, Carlos O'Donell wrote:
> > On 10/12/2013 04:25 AM, OndÅej BÃlka wrote:
> > > Hi,
> > >
> > > This is another bug in glob with patch in bugzilla from Tom Lee ready,
> > > see https://sourceware.org/bugzilla/show_bug.cgi?id=866
> > >
> > > Patch itself is ok, what is left is decide if listing dangling symlinks
> > > is desired behavior.
> > >
> > > Comments?
> >
> > This patch looks good to me. We definitely want to match dangling
> > symlinks. I see that Rich agrees with me in #5 of the issue.
> >
> > The goal here is to make glob match what the shell would do.
> > The shell should match dangling symlinks and so should glob.
> >
> > The more interesting question is should we have some backwards
> > compatibility for old programs? I would say no. It's a bug that
> > we don't do exactly as the shell does and therefore the bug
> > should be fixed for all users of the library.
> >
> > However, this needs a testcase. It needs tst-gnuglob.c to be
> > expanded to handle symlinks and then add a dangling symlink
> > and show that we capture it in the glob. That shouldn't be too
> > much more work since the infrastructure is all there.
> >
> Actually this is tested by existing test that needs to be modified.
>
>
> diff --git a/posix/bug-glob1.c b/posix/bug-glob1.c
> index 05c2da7..5baf0a1 100644
> --- a/posix/bug-glob1.c
> +++ b/posix/bug-glob1.c
> @@ -60,15 +60,28 @@ do_test (void)
> }
> 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);
> +
> +
> +
> size_t fnamelen = strlen (fname);
> char buf[fnamelen + 2];
>
> strcpy (buf, fname);
> buf[fnamelen - 1] = '?';
> e = glob (buf, 0, NULL, &gl);
> - if (e == 0)
> + if (e != 0)
> {
> - printf ("glob(\"%s\") succeeded\n", buf);
> + printf ("glob(\"%s\") failed\n", buf);
> retval = 1;
> }
> globfree (&gl);
> @@ -77,9 +90,9 @@ do_test (void)
> buf[fnamelen] = '*';
> buf[fnamelen + 1] = '\0';
> e = glob (buf, 0, NULL, &gl);
> - if (e == 0)
> + if (e != 0)
> {
> - printf ("glob(\"%s\") succeeded\n", buf);
> + printf ("glob(\"%s\") failed\n", buf);
> retval = 1;
> }
> globfree (&gl);
> diff --git a/posix/glob.c b/posix/glob.c
> index 85237c2..cd07c13 100644
> --- a/posix/glob.c
> +++ b/posix/glob.c
> @@ -203,7 +203,7 @@ static const char *next_brace_sub (const char *begin, int flags) __THROWNL;
>
> static int glob_in_dir (const char *pattern, const char *directory,
> int flags, int (*errfunc) (const char *, int),
> - glob_t *pglob, size_t alloca_used);
> + glob_t *pglob, size_t alloca_used, int chklnks);
> extern int __glob_pattern_type (const char *pattern, int quote)
> attribute_hidden;
>
> @@ -1082,7 +1082,7 @@ glob (pattern, flags, errfunc, pglob)
> status = glob_in_dir (filename, dirs.gl_pathv[i],
> ((flags | GLOB_APPEND)
> & ~(GLOB_NOCHECK | GLOB_NOMAGIC)),
> - errfunc, pglob, alloca_used);
> + errfunc, pglob, alloca_used, 1);
> if (status == GLOB_NOMATCH)
> /* No matches in this directory. Try the next. */
> continue;
> @@ -1189,7 +1189,7 @@ glob (pattern, flags, errfunc, pglob)
> if (dirname_modified)
> flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC);
> status = glob_in_dir (filename, dirname, flags, errfunc, pglob,
> - alloca_used);
> + alloca_used, 0);
> if (status != 0)
> {
> if (status == GLOB_NOMATCH && flags != orig_flags
> @@ -1466,7 +1466,7 @@ link_exists2_p (const char *dir, size_t dirlen, const char *fname,
> static int
> glob_in_dir (const char *pattern, const char *directory, int flags,
> int (*errfunc) (const char *, int),
> - glob_t *pglob, size_t alloca_used)
> + glob_t *pglob, size_t alloca_used, int chklnks)
> {
> size_t dirlen = strlen (directory);
> void *stream = NULL;
> @@ -1609,8 +1609,8 @@ glob_in_dir (const char *pattern, const char *directory, int flags,
> /* If the file we found is a symlink we have to
> make sure the target file exists. */
> if (!DIRENT_MIGHT_BE_SYMLINK (d)
> - || link_exists_p (dfd, directory, dirlen, name, pglob,
> - flags))
> + || (chklnks ? link_exists_p (dfd, directory, dirlen, name, pglob,
> + flags) : 1))
> {
> if (cur == names->count)
> {
--
We're upgrading /dev/null