From dada@sbox.tugraz.at  Mon Jan  8 10:42:36 2007
Return-Path: <dada@sbox.tugraz.at>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 0FE9B16A40F
	for <freebsd-gnats-submit@freebsd.org>; Mon,  8 Jan 2007 10:42:36 +0000 (UTC)
	(envelope-from dada@sbox.tugraz.at)
Received: from mailrelay2.tugraz.at (mailrelay.tu-graz.ac.at [129.27.2.202])
	by mx1.freebsd.org (Postfix) with ESMTP id A7FD213C461
	for <freebsd-gnats-submit@freebsd.org>; Mon,  8 Jan 2007 10:42:35 +0000 (UTC)
	(envelope-from dada@sbox.tugraz.at)
Received: from webmail.tugraz.at (webmail.tu-graz.ac.at [129.27.2.204])
	by mailrelay2.tugraz.at (8.13.8/8.13.8) with ESMTP id l08A8IMQ008498
	for <freebsd-gnats-submit@freebsd.org>; Mon, 8 Jan 2007 11:08:18 +0100 (CET)
Received: from AWP472.kfunigraz.ac.at (AWP472.kfunigraz.ac.at
	[143.50.80.72]) by webmail.tugraz.at (Horde MIME library) with HTTP; Mon,
	08 Jan 2007 11:08:18 +0100
Message-Id: <20070108110818.3pf6e29bcoswg48g@webmail.tugraz.at>
Date: Mon, 08 Jan 2007 11:08:18 +0100
From: Martin Kammerhofer <dada@sbox.tugraz.at>
To: FreeBSD problem reports <freebsd-gnats-submit@freebsd.org>
Subject: sh(1): "type /NONEXISTENT" returns success

>Number:         107673
>Category:       bin
>Synopsis:       sh(1): "type /NONEXISTENT" returns success
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 08 10:50:08 GMT 2007
>Closed-Date:    Mon Jan 08 14:38:11 GMT 2007
>Last-Modified:  Mon Jan 08 14:38:11 GMT 2007
>Originator:     =09Martin Kammerhofer <mkamm@gmx.net>
>Release:        =09FreeBSD 6.2-PRERELEASE i386
>Organization:
=09
>Environment:
System: FreeBSD Martin.liebt.Susi 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #2: =
Tue Dec 5 13:15:11 CET 2006 toor@Martin.liebt.Susi:/usr/src/sys/i386/compile=
/P2B-S i386
>Description:

The type shell builtin indicates how each argument would be
interpreted if used as a command name. Shell scripts frequently
redirect the output to /dev/null and take a zero exit code as
confirmation that a command is available. (Similar to "test -x" which
only works with a single path name argument.)

Our sh(1) "forgets" to set the return code ($?) when testing a path
name argument, i.e. something containing the slash (/)
character. Therefore all such tests succeed unconditionally!

This e.g. breaks the hgmerge script installed with the devel/mercurial
port (when there are merge conflicts).

>How-To-Repeat:
$ /bin/sh -c "type /foo/bar && echo WE HAVE FOOBAR"
/foo/bar: No such file or directory
WE HAVE FOOBAR
$ /bin/sh -c "type /* && echo WE HAVE MANY COMMANDS IN /"

>Fix:
Index: exec.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/bin/sh/exec.c,v
retrieving revision 1.29
diff -u -r1.29 exec.c
--- exec.c=099 Apr 2006 12:21:20 -0000=091.29
+++ exec.c=096 Jan 2007 21:47:12 -0000
@@ -780,14 +780,16 @@
 =09=09=09=09=09=09" a tracked alias for" : "",
 =09=09=09=09=09    name);
 =09=09=09} else {
-=09=09=09=09if (access(argv[i], X_OK) =3D=3D 0) {
+=09=09=09=09if (eaccess(argv[i], X_OK) =3D=3D 0) {
 =09=09=09=09=09if (cmd =3D=3D TYPECMD_SMALLV)
 =09=09=09=09=09=09out1fmt("%s\n", argv[i]);
 =09=09=09=09=09else
 =09=09=09=09=09=09out1fmt(" is %s\n", argv[i]);
 =09=09=09=09}
-=09=09=09=09else
+=09=09=09=09else {
 =09=09=09=09=09out1fmt(": %s\n", strerror(errno));
+=09=09=09=09=09error |=3D 127;
+=09=09=09=09}
 =09=09=09}
 =09=09=09break;
 =09=09}

--=_21vtg4rjt728--

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Mon Jan 8 14:37:25 UTC 2007 
State-Changed-Why:  
Badly formatted version of 107674. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=107673 
>Unformatted:
 This message is in MIME format.
 
 --=_21vtg4rjt728
 Content-Type: text/plain;
 	charset=ISO-8859-1;
 	DelSp="Yes";
 	format="flowed"
 Content-Disposition: inline
 Content-Transfer-Encoding: 7bit
 
 
 
 --=_21vtg4rjt728
 Content-Type: text/plain;
 	charset=UTF-8;
 	name="sh-type.PR"
 Content-Disposition: inline;
 	filename="sh-type.PR"
 Content-Transfer-Encoding: quoted-printable
 
