From dan@dan.emsphone.com  Sun Sep 22 19:54:23 2002
Return-Path: <dan@dan.emsphone.com>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id 8BE4637B401; Sun, 22 Sep 2002 19:54:23 -0700 (PDT)
Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id 19CB943E3B; Sun, 22 Sep 2002 19:54:23 -0700 (PDT)
	(envelope-from dan@dan.emsphone.com)
Received: (from dan@localhost)
	by dan.emsphone.com (8.12.6/8.12.5) id g8N2sMmf049380;
	Sun, 22 Sep 2002 21:54:22 -0500 (CDT)
	(envelope-from dan)
Message-Id: <200209230254.g8N2sMmf049380@dan.emsphone.com>
Date: Sun, 22 Sep 2002 21:54:22 -0500 (CDT)
From: Dan Nelson <dnelson@allantgroup.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: tjr@freebsd.org
Subject: [PATCH] ash cannot parse "case hello in \n esac"
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         43275
>Category:       bin
>Synopsis:       [PATCH] ash cannot parse "case hello in \n esac"
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    tjr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 22 20:00:09 PDT 2002
>Closed-Date:    Fri Oct 18 04:25:03 PDT 2002
>Last-Modified:  Fri Oct 18 04:25:03 PDT 2002
>Originator:     Dan Nelson
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
The Allant Group
>Environment:
System: FreeBSD dan.emsphone.com 5.0-CURRENT FreeBSD 5.0-CURRENT #191: Tue Sep 17 17:38:00 CDT 2002 zsh@dan.emsphone.com:/usr/src/sys/i386/compile/DANSMP i386


	
>Description:

/bin/sh is current coded to require a pattern inside a case/esac block,
where it's really optional.

	
>How-To-Repeat:

$ /bin/sh
$ case hello in 
> esac
> [^D]Syntax error: end of file unexpected (expecting ")")
$ 

	
>Fix:

This is a partial fix.  With this, "case hello in \n esac" works, but
"case hello in ; esac" doesn't, and I think it should.  Half a fix is
better than none though.

This fix also will close PR ports/35879.

Index: parser.c
===================================================================
RCS file: /home/ncvs/src/bin/sh/parser.c,v
retrieving revision 1.44
diff -u -p -r1.44 parser.c
--- parser.c	25 Aug 2002 13:01:47 -0000	1.44
+++ parser.c	23 Sep 2002 02:41:46 -0000
@@ -429,7 +429,7 @@ TRACE(("expecting DO got %s %s\n", tokna
 		cpp = &n1->ncase.cases;
 		noaliases = 1;	/* turn off alias expansion */
 		checkkwd = 2, readtoken();
-		do {
+		while (lasttoken != TESAC) {
 			*cpp = cp = (union node *)stalloc(sizeof (struct nclist));
 			cp->type = NCLIST;
 			app = &cp->nclist.pattern;
@@ -456,7 +456,7 @@ TRACE(("expecting DO got %s %s\n", tokna
 					checkkwd = 2, readtoken();
 			}
 			cpp = &cp->nclist.next;
-		} while(lasttoken != TESAC);
+		} 
 		noaliases = 0;	/* reset alias expansion */
 		*cpp = NULL;
 		checkkwd = 1;

	


>Release-Note:
>Audit-Trail:

From: Tony Finch <dot@dotat.at>
To: dnelson@allantgroup.com
Cc: tjr@freebsd.org, freebsd-gnats-submit@freebsd.org
Subject: Re: bin/43275: [PATCH] ash cannot parse "case hello in \n esac"
Date: Mon, 23 Sep 2002 17:58:29 +0100

 Dan Nelson <dnelson@allantgroup.com> wrote:
 >
 >/bin/sh is current coded to require a pattern inside a case/esac block,
 >where it's really optional.
 
 My reading of SUSv3 disagrees with you. SUSv2 is ambiguous.
 
 Tony.
 -- 
 f.a.n.finch <dot@dotat.at> http://dotat.at/
 FAEROES SOUTHEAST ICELAND: SOUTHWESTERLY 4 OR 5. RAIN OR DRIZZLE. MODERATE OR
 POOR.
Responsible-Changed-From-To: freebsd-bugs->tjr 
Responsible-Changed-By: johan 
Responsible-Changed-When: Sun Sep 29 10:22:52 PDT 2002 
Responsible-Changed-Why:  
Tim as somewhat of sh and standars guru, can you please have 
a look at this PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43275 

From: Tim Robbins <tjr@freebsd.org>
To: dnelson@allantgroup.com
Cc: freebsd-gnats-submit@freebsd.org, Tony Finch <dot@dotat.at>,
	johan@freebsd.org
Subject: Re: bin/43275: [PATCH] ash cannot parse "case hello in \n esac"
Date: Mon, 30 Sep 2002 12:14:59 +1000

 There is a defect in the standard here. In Shell and Utilities Issue 6,
 page 59 line 2408, the grammar they give would accept
 
 case <word> in <newline> esac
 
 as a valid command. However, on line 2145 it says that a case block needs
 to have at least one pattern and compound list.
 
 It also says above the grammar:
 
 2240 2.10 Shell Grammar
 2241 The following grammar defines the Shell Command Language. This formal
      syntax shall take
 2242 precedence over the preceding text syntax description.
 
 So I'll probably commit the patch, as well as fix another bug in the parsing
 of `case':
 
 case a in
 (b) echo c
 esac
 
 .. does not work.
 
 
 Tim
State-Changed-From-To: open->patched 
State-Changed-By: tjr 
State-Changed-When: Mon Sep 30 03:58:20 PDT 2002 
State-Changed-Why:  
Patch committed, thanks. I'll MFC it some time before 4.8. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43275 
State-Changed-From-To: patched->closed 
State-Changed-By: tjr 
State-Changed-When: Fri Oct 18 04:24:35 PDT 2002 
State-Changed-Why:  
Change has been MFC'd, thanks. 

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