NetBSD Problem Report #47608

From kre@munnari.OZ.AU  Sat Mar  2 18:29:38 2013
Return-Path: <kre@munnari.OZ.AU>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id 4A95163C07C
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  2 Mar 2013 18:29:38 +0000 (UTC)
Message-Id: <201303021828.r22ISGKo016712@jade.coe.psu.ac.th>
Date: Sun, 3 Mar 2013 01:28:16 +0700 (ICT)
From: kre@munnari.OZ.AU
To: gnats-bugs@gnats.NetBSD.org
Subject: ``var=value func-call'' does not export var in the function (+FIX)
X-Send-Pr-Version: 3.95

>Number:         47608
>Category:       bin
>Synopsis:       ``var=value func-call'' does not export var in the function (+FIX)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 02 18:30:00 +0000 2013
>Closed-Date:    Tue Sep 08 09:11:27 +0000 2015
>Last-Modified:  Tue Sep 08 09:11:27 +0000 2015
>Originator:     Robert Elz
>Release:        NetBSD  (current as of 2013-03-02 & all earlier supported versions)
>Organization:
	Prince of Songkla University
>Environment:
System: NetBSD jade.coe.psu.ac.th 5.1_STABLE NetBSD 5.1_STABLE (JADE-1.12-20120130) #27: Tue Jan 31 05:20:31 ICT 2012 kre@jade.coe.psu.ac.th:/usr/obj/5/kernels/i386/JADE i386
Architecture: i386
Machine: i386
>Description:
	The syntax
		var=value command
	is supposed to add var (with value "value") to the environment
	of command.   If command is an executable, it does.  If
	command is a function, it doesn't - the function gets to see
	the value of ${var} as being "value", but any commands it
	runs do not.

>How-To-Repeat:
	unset var
	myfunc() { env | grep '^var=' ; echo "var was ${var} in myfunc"; }
	var=foo myfunc

	The output should be:

	var=foo
	var was foo in myfunc

	But is instead:

	var was foo in myfunc

	The "env" invocation does not send a value for "var" to grep.

	Note this is (kind of) related to the long discussion on
	tech-userlevel on what should be the value in var after myfunc
	finishes,  but this one is much simpler, non-controversial,
	and clearly a bug in our sh.

>Fix:
	Apply the patch below.   It is kind of trivial, but works...

--- eval.c.bug	2013-01-03 15:54:42.000000000 +0700
+++ eval.c	2013-03-03 01:00:48.000000000 +0700
@@ -947,7 +947,7 @@
 		}
 		savehandler = handler;
 		handler = &jmploc;
-		listmklocal(varlist.list, 0);
+		listmklocal(varlist.list, VEXPORT);
 		/* stop shell blowing its stack */
 		if (++funcnest > 1000)
 			error("too many nested function calls");

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/47608 CVS commit: src/bin/sh
Date: Sat, 2 Mar 2013 17:02:33 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sat Mar  2 22:02:33 UTC 2013

 Modified Files:
 	src/bin/sh: eval.c

 Log Message:
 PR/47608: Robert Elz: ``var=value func-call'' does not export var in the
 function (+FIX)


 To generate a diff of this commit:
 cvs rdiff -u -r1.105 -r1.106 src/bin/sh/eval.c

 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: dholland@NetBSD.org
State-Changed-When: Tue, 08 Sep 2015 09:11:27 +0000
State-Changed-Why:
christos fixed it in 2013


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.