From owner-freebsd-bugs@FreeBSD.ORG Tue Mar 31 23:10:02 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 31A461065670 for ; Tue, 31 Mar 2009 23:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 0CFD88FC25 for ; Tue, 31 Mar 2009 23:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n2VNA18m014273 for ; Tue, 31 Mar 2009 23:10:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n2VNA1x7014272; Tue, 31 Mar 2009 23:10:01 GMT (envelope-from gnats) Resent-Date: Tue, 31 Mar 2009 23:10:01 GMT Resent-Message-Id: <200903312310.n2VNA1x7014272@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jilles Tjoelker Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D9B2510656C4 for ; Tue, 31 Mar 2009 23:03:19 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (unknown [IPv6:2001:610:1108:5000::149]) by mx1.freebsd.org (Postfix) with ESMTP id 9A43C8FC1F for ; Tue, 31 Mar 2009 23:03:19 +0000 (UTC) (envelope-from jilles@stack.nl) Received: by mx1.stack.nl (Postfix, from userid 65534) id 594F53F6D7; Wed, 1 Apr 2009 01:03:18 +0200 (CEST) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 8093A3F693 for ; Wed, 1 Apr 2009 01:03:16 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id D2EDF2289C; Wed, 1 Apr 2009 01:03:03 +0200 (CEST) Message-Id: <20090331230303.D2EDF2289C@snail.stack.nl> Date: Wed, 1 Apr 2009 01:03:03 +0200 (CEST) From: Jilles Tjoelker To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/133255: [PATCH] sh: empty line in eval resets $? X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Mar 2009 23:10:02 -0000 >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: