Date: Wed, 1 Apr 2009 01:03:03 +0200 (CEST) From: Jilles Tjoelker <jilles@stack.nl> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/133255: [PATCH] sh: empty line in eval resets $? Message-ID: <20090331230303.D2EDF2289C@snail.stack.nl> Resent-Message-ID: <200903312310.n2VNA1x7014272@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 133255 >Category: bin >Synopsis: [PATCH] sh: empty line in eval resets $? >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Mar 31 23:10:01 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Jilles Tjoelker >Release: FreeBSD 7.2-PRERELEASE i386 >Organization: MCGV Stack >Environment: bug seems to be present in -CURRENT also >Description: An empty line in the text passed to 'eval' and 'trap' and to the '-c' option causes sh to forget the exit status of the previous command. 'fc' may be affected as well. This only happens if the the empty line is at the top level of the string (not in {}, if and the like). git sometimes does this, with eval. This may cause a test to succeed when it has really failed. Other shells preserve the exit status in this case. >How-To-Repeat: Input: (to /bin/sh) (the empty line between 'false and '; is significant) eval 'false '; echo $? Expected result: 1 Actual result: 0 Two other inputs with the same property: eval 'false echo $?' sh -c 'false echo $?' An input not affected by the bug: eval '{ false echo $? }' properly prints 1. >Fix: The following patch is inspired by how empty lines are ignored in shell scripts and in interactive mode (in either case, the exit status is preserved). I have run a 7.x buildworld/installworld and various configure scripts with this, and have not noticed any problems. --- sh-eval-emptyline.patch begins here --- --- src/bin/sh/eval.c.orig 2008-09-04 19:34:53.000000000 +0200 +++ src/bin/sh/eval.c 2009-03-22 22:20:17.000000000 +0100 @@ -166,7 +166,8 @@ setstackmark(&smark); setinputstring(s, 1); while ((n = parsecmd(0)) != NEOF) { - evaltree(n, 0); + if (n != NULL) + evaltree(n, 0); popstackmark(&smark); } popfile(); --- sh-eval-emptyline.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090331230303.D2EDF2289C>