From owner-freebsd-bugs@FreeBSD.ORG Mon Jan 8 11:00:32 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8907416A4C8 for ; Mon, 8 Jan 2007 11:00:32 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 3902D13C43E for ; Mon, 8 Jan 2007 11:00:30 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l08B0UW4015128 for ; Mon, 8 Jan 2007 11:00:30 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l08B0Utd015126; Mon, 8 Jan 2007 11:00:30 GMT (envelope-from gnats) Resent-Date: Mon, 8 Jan 2007 11:00:30 GMT Resent-Message-Id: <200701081100.l08B0Utd015126@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Martin Kammerhofer Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 72EAC16A412 for ; Mon, 8 Jan 2007 10:53:54 +0000 (UTC) (envelope-from dada@pluto.tugraz.at) Received: from mailrelay1.tugraz.at (mailrelay.tu-graz.ac.at [129.27.2.202]) by mx1.freebsd.org (Postfix) with ESMTP id 05E5C13C455 for ; Mon, 8 Jan 2007 10:53:53 +0000 (UTC) (envelope-from dada@pluto.tugraz.at) Received: from pluto.tugraz.at (pluto.tu-graz.ac.at [129.27.3.200]) by mailrelay1.tugraz.at (8.13.8/8.13.8) with ESMTP id l08AroLi024202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 8 Jan 2007 11:53:50 +0100 (CET) Received: from pluto.tugraz.at (localhost.localdomain [127.0.0.1]) by pluto.tugraz.at (8.13.1/8.13.1) with ESMTP id l08AriQv007661 for ; Mon, 8 Jan 2007 11:53:44 +0100 Received: (from dada@localhost) by pluto.tugraz.at (8.13.1/8.13.1/Submit) id l08ArhYx007660 for freebsd-gnats-submit@freebsd.org; Mon, 8 Jan 2007 11:53:43 +0100 Message-Id: <200701081053.l08ArhYx007660@pluto.tugraz.at> Date: Mon, 8 Jan 2007 11:53:43 +0100 From: Martin Kammerhofer To: freebsd-gnats-submit@FreeBSD.org Cc: Subject: bin/107674: sh(1): "type /NONEXISTENT" returns success X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jan 2007 11:00:32 -0000 >Number: 107674 >Category: bin >Synopsis: sh(1): "type /NONEXISTENT" returns success >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Jan 08 11:00:29 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Martin Kammerhofer >Release: FreeBSD 6.2-PRERELEASE i386 >Organization: >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 =================================================================== RCS file: /home/ncvs/src/bin/sh/exec.c,v retrieving revision 1.29 diff -u -r1.29 exec.c --- exec.c 9 Apr 2006 12:21:20 -0000 1.29 +++ exec.c 6 Jan 2007 21:47:12 -0000 @@ -780,14 +780,16 @@ " a tracked alias for" : "", name); } else { - if (access(argv[i], X_OK) == 0) { + if (eaccess(argv[i], X_OK) == 0) { if (cmd == TYPECMD_SMALLV) out1fmt("%s\n", argv[i]); else out1fmt(" is %s\n", argv[i]); } - else + else { out1fmt(": %s\n", strerror(errno)); + error |= 127; + } } break; } >Release-Note: >Audit-Trail: >Unformatted: