From owner-freebsd-bugs Sat Dec 9 09:50:05 1995 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id JAA04445 for bugs-outgoing; Sat, 9 Dec 1995 09:50:05 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id JAA04439 Sat, 9 Dec 1995 09:50:03 -0800 (PST) Resent-Date: Sat, 9 Dec 1995 09:50:03 -0800 (PST) Resent-Message-Id: <199512091750.JAA04439@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, nnd@itfs.nsk.su Received: from gw.itfs.nsk.su (gw.itfs.nsk.su [193.124.36.33]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id JAA04143 for ; Sat, 9 Dec 1995 09:40:35 -0800 (PST) Received: from itfs.UUCP (uucp@localhost) by gw.itfs.nsk.su (8.6.12/8.6.12) with UUCP id XAA14879 for FreeBSD-gnats-submit@freebsd.org; Sat, 9 Dec 1995 23:40:07 +0600 Received: by itfs.nsk.su; Sat, 9 Dec 95 23:32:56 +0600 (NSK) Received: (from root@localhost) by info.itfs.nsk.su (8.6.11/8.6.9) id XAA16125; Sat, 9 Dec 1995 23:28:06 +0600 Message-Id: <199512091728.XAA16125@info.itfs.nsk.su> Date: Sat, 9 Dec 1995 23:28:06 +0600 From: nnd@itfs.nsk.su Reply-To: nnd@itfs.nsk.su To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/880: /bin/sh incorrectly parse command lists Sender: owner-bugs@freebsd.org Precedence: bulk >Number: 880 >Category: bin >Synopsis: Incorrect parsing of command lists by /bin/sh >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Dec 9 09:50:01 PST 1995 >Last-Modified: >Originator: Nickolay N. Dudorov >Organization: Infoteka Ltd. >Release: FreeBSD 2.0-BUILT-19950524 i386 >Environment: FreeBSD versions from 1.1 to 2.2-current >Description: /bin/sh (ash) incorrectly parse command lists if any (but not first) of list components marked as 'background', f.e construction { a; b; c & d; e; } parsed as if it was { { a; b; c; } & d; e; } All other shells which I can test parse this as { a; b; { c& } ; d; e; } (including /bin/sh in NetBSD-current which is originated from the same sources as FreeBSD one) >How-To-Repeat: Try this one: #!/bin/sh while true do date +'1:%H:%M:%S' sleep 2 exit ps jx & date +'2:%H:%M:%S' sleep 3 exit done (while ... do ... done is here to force using command-list ) >Fix: Applay the patch. (Here is the result of diff -u /usr/src/bin/sh/parse.c.ORG /usr/src/bin/sh/parse.c) --- /usr/src/bin/sh/parser.c.ORG Wed Aug 30 15:44:33 1995 +++ /usr/src/bin/sh/parser.c Tue Dec 5 18:56:28 1995 @@ -149,30 +149,13 @@ n1 = andor(); for (;;) { switch (readtoken()) { - case TBACKGND: - if (n1->type == NCMD || n1->type == NPIPE) { - n1->ncmd.backgnd = 1; - } else if (n1->type == NREDIR) { - n1->type = NBACKGND; - } else { - n3 = (union node *)stalloc(sizeof (struct nredir)); - n3->type = NBACKGND; - n3->nredir.n = n1; - n3->nredir.redirect = NULL; - n1 = n3; - } - goto tsemi; case TNL: - tokpushback++; + parseheredoc(); + if (nlflag) + return n1; /* fall through */ -tsemi: case TSEMI: - if (readtoken() == TNL) { - parseheredoc(); - if (nlflag) - return n1; - } else { - tokpushback++; - } + case TBACKGND: + case TSEMI: checkkwd = 2; if (tokendlist[peektoken()]) return n1; @@ -212,6 +195,19 @@ } else if (t == TOR) { t = NOR; } else { + if (t == TBACKGND) { + if (n1->type == NCMD || n1->type == NPIPE) { + n1->ncmd.backgnd = 1; + } else if (n1->type == NREDIR) { + n1->type = NBACKGND; + } else { + n3 = (union node *)stalloc(sizeof (struct nredir)); + n3->type = NBACKGND; + n3->nredir.n = n1; + n3->nredir.redirect = NULL; + n1 = n3; + } + } tokpushback++; return n1; } >Audit-Trail: >Unformatted: