Bug 126460 - glob does not match dead symlinks
Summary: glob does not match dead symlinks
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc   
(Show other bugs)
Version: 2
Hardware: i686
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Keywords: Patch
Depends On:
TreeView+ depends on / blocked
Reported: 2004-06-21 23:12 UTC by Daniel Hokka Zakrisson
Modified: 2017-03-06 22:33 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-09-30 06:39:58 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Test case. (761 bytes, text/plain)
2004-06-21 23:13 UTC, Daniel Hokka Zakrisson
no flags Details
Patch to make glob_in_dir use __lstat64 instead of __stat64 (649 bytes, patch)
2004-06-22 15:29 UTC, Daniel Hokka Zakrisson
no flags Details | Diff

External Trackers
Tracker ID Priority Status Summary Last Updated
Sourceware 866 None None None 2017-03-06 22:33 UTC

Description Daniel Hokka Zakrisson 2004-06-21 23:12:36 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1)

Description of problem:
When running glob with a pattern that is a filename, with the filename
referring to a dead symlink, glob returns GLOB_NOMATCH.
See the attached testcase.

Version-Release number of selected component (if applicable):
glibc-2.3.3-27, glibc-2.3.2-101.4

How reproducible:

Steps to Reproduce:
1. Compile testcase.c and run a.out.

Actual Results:  glob returned 3

Expected Results:  There should be no output.

Additional info:

Comment 1 Daniel Hokka Zakrisson 2004-06-21 23:13:42 UTC
Created attachment 101318 [details]
Test case.

Comment 2 Jakub Jelinek 2004-06-22 13:02:30 UTC
Why do you think so?
Current glibc behaviour certainly matches e.g. Solaris glob behaviour.

Comment 3 Daniel Hokka Zakrisson 2004-06-22 13:46:35 UTC
Because it is matched by "dead-link*" and "dead-lin?".
I wouldn't complain if the behaviour was consistent, to not match dead
symlinks at all, but as they are matched if the pattern is indeed a
pattern, I think it's a bug.

Comment 4 Daniel Hokka Zakrisson 2004-06-22 15:29:11 UTC
Created attachment 101335 [details]
Patch to make glob_in_dir use __lstat64 instead of __stat64

The patch is against the glibc CVS.
(side note: shouldn't the __stat64/__lstat64 be in an ifdef HAVE_STAT64

Comment 5 Ulrich Drepper 2004-09-30 06:39:58 UTC
Actually, dead-link* and dead-lin? should not match.  I've made
appropriate changes in the upstream glibc.  The result will appear in
rawhide soon.

Comment 6 Arkadiusz Miskiewicz 2004-11-21 22:17:01 UTC
Which standard specifies such dead-symlinks glob() behaviour? I'm 
currently looking into http://www.opengroup.org/onlinepubs/009695399/
functions/glob.html and see no information about such specific case.

Comment 7 Derek Price 2005-06-01 16:14:38 UTC
I disagree that the dead link should not be returned.  This may be the behavior
on Solaris 8 through 10, but it is not the behavior on BSD and it disagrees with
the POSIX2 spec (http://www.opengroup.org/onlinepubs/009695399/functions/glob.html).

Nowhere does the POSIX2 glob spec specify that a broken symlink should not be
considered an "existing pathname".  After all, the link exists, only its target
does not.  Interpreted in this way, glob cannot be used by a program which, for
instance, wished to verify that all links matching a pattern had valid targets
since the broken links would not be returned by glob.

If glob is only going to consider a link as if it is its target, then what about
the case where a matching link points to a file in the same directory that also
matches the pattern?  Should glob only return one or the other?

Perhaps a GNU extension similar to GLOB_ONLYDIR is in order
(GLOB_VERIFY_SYMLINKS?), but I do not think glob should be making these value
judgements when the user did not request it.  It certainly does not appear to be
implied by the POSIX spec as I read it.

I have a patch for this issue including some efficiency improvements, but will
hold onto it until we finish the discussion of its applicability.

This bug should be reopened until repaired.

Comment 8 Derek Price 2005-06-01 16:18:54 UTC
Oh, forgot to paste this leader to my last comment:

The POSIX2 glob spec states that glob returns GLOB_NOMATCH only when, "the
pattern does not match any existing pathname, and GLOB_NOCHECK was not set in

Comment 9 Derek Price 2005-06-03 17:43:50 UTC
Paul Eggert cites an even better example:  `Historically, the "*" pattern in the
shell has always matched dangling links.  Otherwise "rm *" wouldn't work as

Paul has said he is preparing my patches for submission to the glibc bugs
mailing list.  If he does not do this within a few days, I will look into doing
it myself.

Comment 10 Michael Schröder 2005-10-20 13:48:18 UTC
If the current (IMHO broken) behavior is kept, the manpage should be changed 
as well. It contains "according to the rules used by the shell", I know of no 
shell that doesn't expand dangling symlinks.  

Note You need to log in before you can comment on or make changes to this bug.