NetBSD Problem Report #52426

From kre@munnari.OZ.AU  Tue Jul 25 01:36:47 2017
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 "mail.NetBSD.org CA" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id D1EF27A2A1
	for <gnats-bugs@www.NetBSD.org>; Tue, 25 Jul 2017 01:36:46 +0000 (UTC)
Message-Id: <201707250136.v6P1aWkH004206@andromeda.noi.kre.to>
Date: Tue, 25 Jul 2017 08:36:32 +0700 (ICT)
From: kre@munnari.OZ.AU
To: gnats-bugs@www.NetBSD.org
Subject: Undetected syntax errors in /bin/sh
X-Send-Pr-Version: 3.95

>Number:         52426
>Category:       bin
>Synopsis:       Undetected syntax errors in /bin/sh
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kre
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 25 01:40:00 +0000 2017
>Closed-Date:    Wed Jul 26 23:10:23 +0000 2017
>Last-Modified:  Wed Jul 26 23:10:23 +0000 2017
>Originator:     Robert Elz
>Release:        NetBSD 8.99.1
>Organization:
>Environment:
		Irrelevant, any NetBSD /bin/sh (forever).
>Description:
	sh accepts both of these lines of nonsense, without error

		: ; }

		case x in <|() ;; esac

	Both can also be observed in dash and the second in the FreeBSD sh.
	They are very old ash bugs (FreeBSD have fixed the first one.)

>How-To-Repeat:
	Just use input something like one of the above.
>Fix:
  Workaround:  Don't write gibberish sh code.

  Real fix coming soon (as in, already implemented, undergoing testing.)

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: bin-bug-people->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Tue, 25 Jul 2017 01:54:53 +0000
Responsible-Changed-Why:
Mine


State-Changed-From-To: open->analyzed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Tue, 25 Jul 2017 01:56:47 +0000
State-Changed-Why:
Have fixes ready, but combined with more cleanups (doing those was
where I noticed the 2nd issue - just from "strange" code, the first
I had observed, and taken the fix from FreeBSD earlier.)

But because this is parser code, it needs lots of testing before
committing, so it might be a few more days.


From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/52426: Undetected syntax errors in /bin/sh
Date: Tue, 25 Jul 2017 11:11:38 +0700

 For the record note that the first of the "strange syntax" errors
 in this PR is the same problem reported Jan 2014 in PR bin/48498
 and is best characterised as

 	"an invalid reserved word after a ';' (probably: or '&')
 	 is simply disregarded"

 That PR and this will be fixed together.


From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52426 CVS commit: src/tests/bin/sh
Date: Wed, 26 Jul 2017 17:50:21 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Wed Jul 26 17:50:21 UTC 2017

 Modified Files:
 	src/tests/bin/sh: t_syntax.sh

 Log Message:
 PR bin/48498   PR bin/52426

 Add two new sh syntax test cases to check for bug fixes for the parser
 problems (syntax errors unidentified) reported in the two PRs.

 In the latter case, also include some tests that test similar
 looking, valid, syntax - to make sure the fix for the PR does not
 break code that should not fail.  This is not needed for the earlier
 PR as other tests, and just normal parsing, is sufficient.

 These tests have been verified to fail with a current /bin/sh and to
 pass with the sh updates that are to be committed soon -- and because that
 fix is expected within hours, the tests are not marked as expected to
 fail, just let them actually fail for now.


 To generate a diff of this commit:
 cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_syntax.sh

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

From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52426 CVS commit: src/bin/sh
Date: Wed, 26 Jul 2017 23:09:41 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Wed Jul 26 23:09:41 UTC 2017

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

 Log Message:
 PR bin/48498   PR bin/52426

 Don't ignore unexpected reserved words after ';'
 Don't allow any random token type as a case stmt pattern, only a word.
 	Those are ancient ash bugs and do not affect correct scripts.

 Don't ignore redirects in a case stmt list where the list is nothing but
 redirects (if the pattern matches, the redirects should be performed).
 	That was introduced when a redirect only case stmt list was allowed
 	(older shells had generated a syntax error.)

 Random cleanups/refactoring taken from or inspired by the FreeBSD sh
 parser ...  use makename() consistently to create a NARG node - we
 were using it in a couple of places but most NARG node creation was open
 coded.  Introduce consumetoken() (from FreeBSD) to handle the fairly
 common case where exactly one token type must come next, and we need to
 check that, and skip past it when found (or error) and linebreak() (new)
 to handle places where optional \n's are permitted.
 Both previously open coded.

 Simplify list() by removing its second arg, which was only ever used when
 handling the end of a `` (old style command substitution).  Simply move
 the code from inside list() to just after its call in the `` case (from
 FreeBSD.)


 To generate a diff of this commit:
 cvs rdiff -u -r1.141 -r1.142 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: analyzed->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Wed, 26 Jul 2017 23:10:23 +0000
State-Changed-Why:
Fixed


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