Date: Sat, 9 Dec 1995 23:28:06 +0600 From: nnd@itfs.nsk.su To: FreeBSD-gnats-submit@freebsd.org Subject: bin/880: /bin/sh incorrectly parse command lists Message-ID: <199512091728.XAA16125@info.itfs.nsk.su> Resent-Message-ID: <199512091750.JAA04439@freefall.freebsd.org>
index | next in thread | raw e-mail
>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:
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199512091728.XAA16125>
