bin/70147: [PATCH] Globbing bug in /bin/sh

Per Hedeland per at hedeland.org
Sat Aug 7 14:30:21 PDT 2004


>Number:         70147
>Category:       bin
>Synopsis:       [PATCH] Globbing bug in /bin/sh
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug 07 21:30:20 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Per Hedeland
>Release:        FreeBSD 5.2-RELEASE i386
>Organization:
>Environment:
System: FreeBSD pluto.hedeland.org 5.2-RELEASE FreeBSD 5.2-RELEASE #1: Sun Jan 18 13:02:43 CET 2004 per at pluto.hedeland.org:/usr/src/sys/i386/compile/PLUTO i386


>Description:
	Globbing in /bin/sh fails to match a dangling symlink. I don't
        know if there is a spec that says that the match should succeed,
        but this behaviour differs from at least FreeBSD /bin/[t]csh,
        bash 2.05b (invoked as 'bash' or 'sh'), Solaris 8 /bin/sh and
        ditto /bin/ksh, and definitely violates the principle of least
        surprise - i.e. there's no doubt that it should be considered a
        bug in my opinion.

>How-To-Repeat:
	$ mkdir /tmp/foo
	$ ln -s baz /tmp/foo/bar
	$ ls -l /tmp/*/bar
	ls: /tmp/*/bar: No such file or directory
	$ 

>Fix:

--- /usr/src/bin/sh/expand.c.ORIG	Sun Aug  3 06:28:10 2003
+++ /usr/src/bin/sh/expand.c	Sat Aug  7 23:14:13 2004
@@ -1166,7 +1166,7 @@
 			if (*p == '\0')
 				break;
 		}
-		if (metaflag == 0 || stat(expdir, &statb) >= 0)
+		if (metaflag == 0 || lstat(expdir, &statb) >= 0)
 			addfname(expdir);
 		return;
 	}



>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list