bin/130298: sh(1) does not handle negation correctly in
complex commands
Jilles Tjoelker
jilles at stack.nl
Sat Apr 4 15:30:04 PDT 2009
The following reply was made to PR bin/130298; it has been noted by GNATS.
From: Jilles Tjoelker <jilles at stack.nl>
To: bug-followup at FreeBSD.org, mb at tns.cz, stefanf at freebsd.org
Cc:
Subject: Re: bin/130298: sh(1) does not handle negation correctly in
complex commands
Date: Sun, 5 Apr 2009 00:28:14 +0200
--C7zPtVaVf+AK4Oqc
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
This is a subtle bug in the parser. It keeps track of whether it should
recognize keywords such as '!' and 'if' (checkkwd global), but it fails
to enable this recognition again after && and ||. Hence, the '!' is not
recognized by pipeline(). Then, command() does enable the recognition
and picks up the '!'. So, cmd1 && ! cmd2 | cmd3 puts the negation on
cmd2 instead of cmd2 | cmd3 and does not work properly. Setting checkkwd
in pipeline() fixes the problem (patch attached).
After I figured this out I noticed NetBSD had already done it, and in
the same way.
http://cvsweb.netbsd.org/bsdweb.cgi/src/bin/sh/parser.c.diff?r1=1.64&r2=1.65&f=h
If the attachment is mangled, try
http://www.stack.nl/~jilles/unix/sh-parser-and-pipe-not.patch
--
Jilles Tjoelker
--C7zPtVaVf+AK4Oqc
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sh-parser-and-pipe-not.patch.txt"
--- src/bin/sh/parser.c.orig 2008-09-04 19:34:53.000000000 +0200
+++ src/bin/sh/parser.c 2009-04-05 00:02:51.000000000 +0200
@@ -250,6 +250,7 @@ pipeline(void)
int negate;
negate = 0;
+ checkkwd = 2;
TRACE(("pipeline: entered\n"));
while (readtoken() == TNOT)
negate = !negate;
--C7zPtVaVf+AK4Oqc--
More information about the freebsd-bugs
mailing list