NetBSD Problem Report #51145

From kre@munnari.OZ.AU  Mon May 16 03:23:02 2016
Return-Path: <kre@munnari.OZ.AU>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(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 D5C7A7AAAE
	for <gnats-bugs@www.NetBSD.org>; Mon, 16 May 2016 03:23:02 +0000 (UTC)
Message-Id: <201605160322.u4G3MfwO006472@andromeda.noi.kre.to>
Date: Mon, 16 May 2016 10:22:41 +0700 (ICT)
From: kre@munnari.OZ.AU
To: gnats-bugs@www.NetBSD.org
Subject: /bin/sh accepts '()' as a valid sub-shell
X-Send-Pr-Version: 3.95

>Number:         51145
>Category:       bin
>Synopsis:       /bin/sh accepts '()' as a valid sub-shell
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kre
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 16 03:25:00 +0000 2016
>Closed-Date:    Wed Jun 01 08:41:07 +0000 2016
>Last-Modified:  Wed Jun 01 08:41:07 +0000 2016
>Originator:     Robert Elz
>Release:        NetBSD 7.99.26 (all versions from historic until fixed)
>Organization:
>Environment:
System: NetBSD andromeda.noi.kre.to 7.99.26 NetBSD 7.99.26 (VBOX64-1.1-20160128) #43: Thu Jan 28 16:09:08 ICT 2016 kre@onyx.coe.psu.ac.th:/usr/obj/current/kernels/amd64/VBOX64 amd64
Architecture: x86_64
Machine: amd64
>Description:
	Note: this is related to (but perhaps not quite the same as)
	PR bin/48489

	A sub-shell
		( ... )
	is supposed to contain a command list, and a command list
	cannot be entirely empty (it can, for example, come close,
	as wth ...
		X= ; ( $X )
	but that's not empty, it just evaluates to nothing, later...

	/bin/sh (NetBSD) (and several other shells) does not object
	to literally nothing (white space does not count) appearing
	inside a sub-shell.   bash, zsh (and even dash, which is derived
	from NetBSD's shell, way back) do.

>How-To-Repeat:
	/bin/sh -c '()'

	There should be an error, and non-zero exit code.  There isn't.

>Fix:
	To be investigated.   The fix committed for 48489 does not fix
	this one, which means that fix might get redone as well (if
	it turns out that one fix can fix both.)

>Release-Note:

>Audit-Trail:
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/51145: /bin/sh accepts '()' as a valid sub-shell
Date: Mon, 16 May 2016 12:15:24 +0700

 To add to my own report, the same problem exists with

 	{ }

 (and to both of these forms with a newline between -  which shouldn't
 make a difference, and doesn't).

 It is interesting that zsh does not object to the form using { (bash
 and dash both do - which mostly guarantees most scripts do not use it.)

 One effect that fixing this might have on some people/scripts is that
 it will no longer be possible to make a truly empty function, like

 f() {
 }

 bash and dash don't permit that, other shells (including NetBSD's) do.
 The shell grammar (in
    http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
 does not permit any of this either.)

 The empty function "rewrite" is 

 f() { :
 }

 or any equivalent form, like: f(){ :;}

Responsible-Changed-From-To: bin-bug-people->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Mon, 16 May 2016 09:14:56 +0000
Responsible-Changed-Why:
I am looking into this PR


From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51145 CVS commit: src/bin/sh
Date: Wed, 1 Jun 2016 02:47:06 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Wed Jun  1 02:47:05 UTC 2016

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

 Log Message:
 PR bin/51145 PR bin/48489
 More fixes to the shell parser to prevent empty simple commands (where
 empty means no significant text at all) - as discussed on tech-userlevel
 this still allows { } (which can be useful in function definitions, not
 really anywhere else though) except in posix mode.  ( ) now generates
 a syntax error, as should any other place where commands are required but
 nothing is present.  (nb, redirections, var assignments, even var expansions
 that expand to nothing, are all OK, and avoid the error - just comments, or
 whits space, are not.)    This is (aside from allowing { } at all) all in
 accordance with the posix spec.


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

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

State-Changed-From-To: open->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Wed, 01 Jun 2016 08:41:07 +0000
State-Changed-Why:
Fixed as much as it is going to be.
{ }
is still permitted in non-posix mode.   ( ) is a syntax
error, as are other completely empty simple commands.


>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.