From mori@tri.asanuma.co.jp  Mon May  8 04:38:37 2000
Return-Path: <mori@tri.asanuma.co.jp>
Received: from vinita.tri.asanuma.co.jp (vinita.tri.asanuma.co.jp [210.160.188.5])
	by hub.freebsd.org (Postfix) with ESMTP id D8AD237B8D6
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  8 May 2000 04:38:34 -0700 (PDT)
	(envelope-from mori@tri.asanuma.co.jp)
Received: from parvati.tri.asanuma.co.jp by vinita.tri.asanuma.co.jp (8.9.3/3.7W) with ESMTP id RAA39434 for <FreeBSD-gnats-submit@freebsd.org>; Mon, 8 May 2000 17:26:45 +0900 (JST)
Received: from kurishna.tri.asanuma.co.jp by parvati.tri.asanuma.co.jp (8.8.8/3.7W) with ESMTP id RAA28344 for <FreeBSD-gnats-submit@freebsd.org>; Mon, 8 May 2000 17:27:16 +0900 (JST)
Received: by kurishna.tri.asanuma.co.jp (8.9.3/3.7W) id RAA68289; Mon, 8 May 2000 17:26:45 +0900 (JST)
Message-Id: <200005080826.RAA68289@kurishna.tri.asanuma.co.jp>
Date: Mon, 8 May 2000 17:26:45 +0900 (JST)
From: mori@tri.asanuma.co.jp
Reply-To: mori@tri.asanuma.co.jp
To: FreeBSD-gnats-submit@freebsd.org
Subject: /bin/sh: wrong parse eval
X-Send-Pr-Version: 3.2

>Number:         18447
>Category:       bin
>Synopsis:       /bin/sh: wrong parse eval
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    cracauer
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 08 04:40:02 PDT 2000
>Closed-Date:    Mon May 15 15:02:49 MEST 2000
>Last-Modified:  Mon May 15 15:03:28 MEST 2000
>Originator:     Koji Mori
>Release:        FreeBSD 3.4-STABLE i386
>Organization:
>Environment:

FreeBSD kurishna.tri.asanuma.co.jp 3.4-STABLE FreeBSD 3.4-STABLE #26: Thu Apr  6 15:48:03 JST 2000     mori@kurishna.tri.asanuma.co.jp:/usr/src/sys/compile/KOTONE  i386


>Description:

This problem is on /bin/sh.

If /bin/sh evaluates a string with `eval' statement and the string
has semicolon at the end, then /bin/sh doesn't process the `eval'
statement.

for example:

  $ /bin/sh -c 'eval echo t'
  t
  $ /bin/sh -c 'eval echo t;'
  $

or

  $ cat test.sh
  #! /bin/sh
  cmd1='eval echo 1;'
  cmd2='eval echo 2'
  eval $cmd1
  eval $cmd2
  $ /bin/sh test.sh
  2
  $

And if the string has multiplue eval statement, then /bin/sh doesn't
process first eval statements, but processes others.

for example:

  $ /bin/sh -c 'eval echo 1; eval echo 2; eval echo 3;'
  2
  3
  $

I think its behavior is /bin/sh's bug.  Other shells reading Bourne
shell script, such as bash or SunOS's /bin/sh, process all eval
statement for above cases.  But NetBSD's /bin/sh is same as FreeBSD.


>How-To-Repeat:

Simple example is

 $ /bin/sh -c 'eval echo 1; eval echo 2;'

The result is

 2

but we expected 

 1
 2


>Fix:

To fix, apply this patch to src/bin/sh/parser.c

diff -u -r1.30 parser.c
--- parser.c	2000/04/20 09:49:16	1.30
+++ parser.c	2000/04/29 01:22:14
@@ -137,6 +137,7 @@
 {
 	int t;
 
+	tokpushback = 0;
 	doprompt = interact;
 	if (doprompt)
 		setprompt(1);

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->cracauer 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Mon May 8 07:41:50 PDT 2000 
Responsible-Changed-Why:  
I'm sure this is a duplicate of another PR, but I can't find the 
imaginary "other PR", so I'm just assigning this to our shell's  
maintainer. 
State-Changed-From-To: open->closed 
State-Changed-By: cracauer 
State-Changed-When: Mon May 15 15:02:49 MEST 2000 
State-Changed-Why:  
Suggested fix applied to -current.  Thanks! 
Will be in 4-stable before 4.1. 
>Unformatted:
