Date: Sat, 4 Apr 2009 22:30:03 GMT From: Jilles Tjoelker <jilles@stack.nl> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/130298: sh(1) does not handle negation correctly in complex commands Message-ID: <200904042230.n34MU3mM009172@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/130298; it has been noted by GNATS. From: Jilles Tjoelker <jilles@stack.nl> To: bug-followup@FreeBSD.org, mb@tns.cz, stefanf@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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904042230.n34MU3mM009172>