From willers@rumori.com  Mon Jul  8 04:04:48 2002
Return-Path: <willers@rumori.com>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id ACB3337B400
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  8 Jul 2002 04:04:48 -0700 (PDT)
Received: from rumori.com (client62-2-193-38.hispeed.ch [62.2.193.38])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 4A4BA43E42
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  8 Jul 2002 04:04:47 -0700 (PDT)
	(envelope-from willers@rumori.com)
Received: (from willers@localhost)
	by rumori.com (8.11.6/8.11.6) id g68B4gR68945;
	Mon, 8 Jul 2002 13:04:42 +0200 (MEST)
	(envelope-from willers)
Message-Id: <200207081104.g68B4gR68945@rumori.com>
Date: Mon, 8 Jul 2002 13:04:42 +0200 (MEST)
From: Moritz Willers <willers@rumori.com>
Reply-To: Moritz Willers <mo@wit.ch>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: closing of file desriptors broken in /bin/sh
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         40334
>Category:       bin
>Synopsis:       closing of file desriptors broken in /bin/sh
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    tjr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 08 04:10:01 PDT 2002
>Closed-Date:    Fri Jul 19 21:15:25 PDT 2002
>Last-Modified:  Fri Jul 19 21:15:25 PDT 2002
>Originator:     Moritz Willers
>Release:        FreeBSD 4.6-RELEASE-p1 i386
>Organization:
>Environment:
System: FreeBSD sand.wit.ch 4.6-RELEASE-p1 FreeBSD 4.6-RELEASE-p1


>Description:
	closing file desriptors via ">&-" in /bin/sh does not work.
	it seems the commits to redir.c going to 4.6 caused this.

	http://www.freebsd.org/cgi/cvsweb.cgi/src/bin/sh/redir.c.diff?r1=1.12.2.1&r2=1.12.2.2

>How-To-Repeat:
	the below command should produce *no* output:

	# uname -r
	4.6-RELEASE-p1
	# /bin/sh -c 'echo "ha" >&-'
	ha
	#

	from the manpage:

            [n]>&-        close stdout (or file descriptor n)


>Fix:
	I did reinsert the close(fd); in line 148 in redir.c which fixed
	the problem, but I do not understand the code in redir.c really,
	so I have no idea about any side effects this could have.

 			if (!try) {
 				sv->renamed[fd] = i;
+				close(fd);
 			}


thanks - Moritz
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->tjr 
Responsible-Changed-By: tjr 
Responsible-Changed-When: Mon Jul 8 08:16:10 PDT 2002 
Responsible-Changed-Why:  
I am working on a patch for this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=40334 
State-Changed-From-To: open->patched 
State-Changed-By: tjr 
State-Changed-When: Tue Jul 9 01:56:01 PDT 2002 
State-Changed-Why:  
Fix committed to -CURRENT, I will MFC it after a week. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=40334 
State-Changed-From-To: patched->closed 
State-Changed-By: tjr 
State-Changed-When: Fri Jul 19 21:15:03 PDT 2002 
State-Changed-Why:  
Change has been MFC'd. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=40334 
>Unformatted:
