NetBSD Problem Report #53550
From kre@munnari.OZ.AU Sat Aug 25 02:42:12 2018
Return-Path: <kre@munnari.OZ.AU>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id D68CA7A155
for <gnats-bugs@gnats.NetBSD.org>; Sat, 25 Aug 2018 02:42:12 +0000 (UTC)
Message-Id: <201808250241.w7P2feve003272@jinx.noi.kre.to>
Date: Sat, 25 Aug 2018 09:41:40 +0700 (+07)
From: kre@munnari.OZ.AU
To: gnats-bugs@NetBSD.org
Subject: /bin/sh exit status of a here-doc only command is incorrect
X-Send-Pr-Version: 3.95
>Number: 53550
>Category: bin
>Synopsis: /bin/sh exit status of a here-doc only command is incorrect
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: kre
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Aug 25 02:45:00 +0000 2018
>Closed-Date: Mon Nov 22 05:28:54 +0000 2021
>Last-Modified: Mon Nov 22 05:28:54 +0000 2021
>Originator: Robert Elz
>Release: NetBSD 8.99.24
>Organization:
>Environment:
System: NetBSD jinx.noi.kre.to 8.99.17 NetBSD 8.99.17 (GENERIC) #1: Sat May 19 20:03:18 ICT 2018 kre@onyx.coe.psu.ac.th:/usr/obj/testing/amd64/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
In the following (useless) command
<<EOF
$(exit 1)
EOF
The exit status should be 1, as POSIX requires that in a command
with no command word (which this is) the exit status shall be
the exit status of the last command substitition performed,
which is the "$(exit 1)" here, which obviously has 1 as its
exit status (or 0 if there is no command substitution).
We ignore the exit status from here doc evaluation, and always
return 0.
>How-To-Repeat:
As above.
>Fix:
No workaround. None really needed, this is a pointless example
that should never arise IRL. Yet, it should be fixed. I noticed
this from reading the code, looking at places where the shell
exits, while fixing PR bin/53548 (which seems, or looks, to be a
related problem, but is not).
This bug has been in the NetBSD sh for ages (it is in netbsd-6
shells, for example). Perhaps forever. Of all modern shells,
zsh is the only other one which does not produce 1 as the exit
status of the empty command with a here doc - and I suspect that
is because they treat it as a shorthand for something else
(perhaps cat - since they also produce a line of output).
I will fix this properly sometime soon... It does not seem urgent.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: bin-bug-people->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Sat, 25 Aug 2018 02:56:15 +0000
Responsible-Changed-Why:
I am looking into this PR
From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/53550 CVS commit: src/bin/sh
Date: Mon, 22 Nov 2021 05:17:43 +0000
Module Name: src
Committed By: kre
Date: Mon Nov 22 05:17:43 UTC 2021
Modified Files:
src/bin/sh: eval.c expand.c expand.h nodetypes redir.c
Log Message:
PR bin/53550
Here we go again... One more time to redo how here docs are
processed (it has been a few years since the last time!)
This is actually a relatively minor change, mostly to timimg
(to just when things happen). Now here docs are expanded at the
same time the "filename" word in a redirect is expanded, rather than
later when the heredoc was being sent to its process. This actually
makes things more consistent - but does break one of the ATF tests
which was testing that we were (effectively) internally inconsistent
in this area.
Not all shells agree on the context in which redirection expansions
should happen, some make any side effects visible to the parent shell
(the majority do) others do the redirection expansions in a subshell
so any side effcts are lost. We used to have a foot in each camp,
with the majority for everything but here docs, and the minority for
here docs. Now we're all the way with LBJ ... (or something like that).
To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/bin/sh/eval.c
cvs rdiff -u -r1.140 -r1.141 src/bin/sh/expand.c
cvs rdiff -u -r1.25 -r1.26 src/bin/sh/expand.h
cvs rdiff -u -r1.19 -r1.20 src/bin/sh/nodetypes
cvs rdiff -u -r1.71 -r1.72 src/bin/sh/redir.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/53550 CVS commit: src/tests/bin/sh
Date: Mon, 22 Nov 2021 05:21:54 +0000
Module Name: src
Committed By: kre
Date: Mon Nov 22 05:21:54 UTC 2021
Modified Files:
src/tests/bin/sh: t_here.sh
Log Message:
PR bin/53550
/bin/sh's processing of here doc expansions has changed. Now it happens
in the context of the parent shell, so side effects are visible there,
just like all other redirection expansions.
We need to stop testing that that doesn't happen, and instead test
that it does. This is that change.
Add another test case which is testing exactly the example from the PR
(well, with a different exit status, 1 is too generic and could happen
by accident) to make sure we don't reintroduce that bug sometime.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/bin/sh/t_here.sh
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Mon, 22 Nov 2021 05:28:54 +0000
State-Changed-Why:
Problem fixed
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.