NetBSD Problem Report #49125

From he@smistad.uninett.no  Tue Aug 19 08:51:59 2014
Return-Path: <he@smistad.uninett.no>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 46C39AE13F
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 19 Aug 2014 08:51:59 +0000 (UTC)
Message-Id: <20140819085154.7EEA63D0B8@smistad.uninett.no>
Date: Tue, 19 Aug 2014 10:51:54 +0200 (CEST)
From: he@NetBSD.org
Reply-To: he@NetBSD.org
To: gnats-bugs@gnats.NetBSD.org
Subject: /bin/sh does not support redirecting to or from FDs > 9
X-Send-Pr-Version: 3.95

>Number:         49125
>Category:       bin
>Synopsis:       /bin/sh does not support redirecting to or from FDs > 9
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 19 08:55:00 +0000 2014
>Closed-Date:    Sun Feb 21 23:13:40 +0000 2016
>Last-Modified:  Sun Feb 21 23:13:40 +0000 2016
>Originator:     Havard Eidnes
>Release:        NetBSD 6.1.4
>Organization:
	None
>Environment:


System: NetBSD smistad.uninett.no 6.1.4 NetBSD 6.1.4 (MAANEN) #2: Sat May 17 15:02:30 CEST 2014 he@smistad.uninett.no:/usr/obj/sys/arch/i386/compile/MAANEN i386
Architecture: i386
Machine: i386
>Description:
	It does not look like our /bin/sh supports redirection to FDs
	with a numeric value above 9:

$ (echo x) 10>/dev/null
sh: Syntax error: word unexpected
$ 
$ echo x 2>&10      
sh: Syntax error: Bad fd number
$ 

	as opposed to

$ echo x 2>&5 
sh: 5: Bad file descriptor
$ 

	Our /bin/ksh also doesn't do this:

$ (echo x) 10>/dev/null
ksh: syntax error: `10' unexpected
ksh: 
$ (echo x) 9>/dev/null
x
$ 

	while bash accepts it willingly:

bash-4.3$ (echo x) 10>/dev/null
x
bash-4.3$ 


>How-To-Repeat:
	See above.

>Fix:
	Looking at the /bin/sh parser.c, it's evident that
	readtoken1() has something to do with this.  I suspect the
	test for len<=2 in this has something to do with it:

        if (eofmark == NULL) {
                if ((c == '>' || c == '<')
                 && quotef == 0
                 && len <= 2
                 && (*out == '\0' || is_digit(*out))) {
                        PARSEREDIR();
                        return lasttoken = TREDIR;
                } else {
                        pungetc();
                }
        }

	If len > 2, a "word" token is returned, and you get the error
	listed in the first example above.

	The handling under the parseredir label also assumes that the
	FD just consists of a single digit, since it just does
	"digit_val(fd)" and "fd" is just a single char.

	The code in fixredir() (same file) is responsible for the "Bad
	fd number" error message, and also assumes just a single
	digit.

	Our sh(1) man page just says "number", and not that it needs
	to be just a single digit.

	The ksh(1) man page does specify, though, that "fd" needs to
	be a single digit with the "<&" and ">&" redirections.  It
	does however look like the ksh(1) man page doesn't actually
	document the "fd>" redirections, although it has an example
	using it at the end of the "Input/Output Redirection" section.

	Whether FDs over 9 are supposed to be supported or whether
	it's a bash extension should be looked into; if our shell
	should not support it, the example in the flock(1) man page
	needs to be fixed, since it doesn't work with either our
	/bin/sh or our /bin/ksh.

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/49125 CVS commit: src/bin/sh
Date: Tue, 19 Aug 2014 08:36:58 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Tue Aug 19 12:36:58 UTC 2014

 Modified Files:
 	src/bin/sh: parser.c

 Log Message:
 PR/49125: Havard Eidnes: /bin/sh does not support redirecting to or from FDs > 9
 According to:
 http://pubs.opengroup.org/onlinepubs/009604599/utilities/xcu_chap02.html#tag_02_07

 Redirection support for fds > 9 is optional but allowed.


 To generate a diff of this commit:
 cvs rdiff -u -r1.90 -r1.91 src/bin/sh/parser.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/49125
Date: Mon, 22 Feb 2016 05:47:31 +0700

 This PR should be closed, Christos fixed it 18 months ago.
 (The commit message is even in the PR)

 kre

State-Changed-From-To: open->closed
State-Changed-By: christos@NetBSD.org
State-Changed-When: Sun, 21 Feb 2016 18:13:40 -0500
State-Changed-Why:
fixed a while ago


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.