From owner-freebsd-current@FreeBSD.ORG Wed Jul 4 15:03:16 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id F3D2716A41F; Wed, 4 Jul 2007 15:03:15 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (nagual.pp.ru [194.87.13.69]) by mx1.freebsd.org (Postfix) with ESMTP id 5C47013C455; Wed, 4 Jul 2007 15:03:15 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (ache@localhost [127.0.0.1]) by nagual.pp.ru (8.14.1/8.14.1) with ESMTP id l64F3DtG031783; Wed, 4 Jul 2007 19:03:13 +0400 (MSD) (envelope-from ache@nagual.pp.ru) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nagual.pp.ru; s=default; t=1183561394; bh=UQ8lbNIPPxbwThL5fu0tTrfoZisBlkZ8+SfsyNF /QLk=; l=2510; h=Received:Date:From:To:Subject:Message-ID: Mail-Followup-To:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:User-Agent; b=i2VKisH/1DMwN/zTMSPA T72m2dxx6oDZTYl+0IutyvS5BGWMum07PMaSOSTUwuqC2WeK/88lDppW+7IA+gm3BAu Nm+CczLUtIX64YBWxvNPDcLsRtsu0qi3PGCijh7uzrEtsDCPSA+4IbOQo4zCczg8eeo TvnU9dWyeLdaxKNVo= Received: (from ache@localhost) by nagual.pp.ru (8.14.1/8.14.1/Submit) id l64F3DKU031782; Wed, 4 Jul 2007 19:03:13 +0400 (MSD) (envelope-from ache) Date: Wed, 4 Jul 2007 19:03:12 +0400 From: Andrey Chernov To: Michal Mertl , freebsd-current , scf@freebsd.org Message-ID: <20070704150312.GB31683@nagual.pp.ru> Mail-Followup-To: Andrey Chernov , Michal Mertl , freebsd-current , scf@freebsd.org References: <1183557221.1799.16.camel@genius.i.cz> <20070704143642.GA31254@nagual.pp.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070704143642.GA31254@nagual.pp.ru> User-Agent: Mutt/1.5.16 (2007-06-09) Cc: Subject: Re: Environment handling broken in /bin/sh with changes to {get,set,put}env() X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2007 15:03:16 -0000 On Wed, Jul 04, 2007 at 06:36:42PM +0400, Andrey Chernov wrote: > 2) "s" may point to getenv()-provided value there. So just modifying it > directly followed by setenv() call will make things inconsistent. > > 3) In my version of patch there was savestr() which copy arg to avoid this > situation. > > Fix will be to restore var.c to mine variant 1.34 You may also try this patch against var.c 1.36: Index: var.c =================================================================== RCS file: /home/ncvs/src/bin/sh/var.c,v retrieving revision 1.36 diff -u -r1.36 var.c --- var.c 4 Jul 2007 00:00:38 -0000 1.36 +++ var.c 4 Jul 2007 14:59:19 -0000 @@ -289,7 +289,7 @@ setvareq(char *s, int flags) { struct var *vp, **vpp; - char *p; + char *p, *ss; int len; if (aflag) @@ -320,10 +320,11 @@ if (vp == &vmpath || (vp == &vmail && ! mpathset())) chkmail(1); if ((vp->flags & VEXPORT) && localevar(s)) { - p = strchr(s, '='); + ss = savestr(s); + p = strchr(ss, '='); *p = '\0'; - (void) setenv(s, p + 1, 1); - *p = '='; + (void) setenv(ss, p + 1, 1); + ckfree(ss); (void) setlocale(LC_ALL, ""); } INTON; @@ -339,10 +340,11 @@ INTOFF; *vpp = vp; if ((vp->flags & VEXPORT) && localevar(s)) { - p = strchr(s, '='); + ss = savestr(s); + p = strchr(ss, '='); *p = '\0'; - (void) setenv(s, p + 1, 1); - *p = '='; + (void) setenv(ss, p + 1, 1); + ckfree(ss); (void) setlocale(LC_ALL, ""); } INTON; @@ -567,7 +569,7 @@ struct var **vpp; struct var *vp; char *name; - char *p; + char *p, *ss; char *cmdname; int ch, values; int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT; @@ -603,10 +605,11 @@ vp->flags |= flag; if ((vp->flags & VEXPORT) && localevar(vp->text)) { - p = strchr(vp->text, '='); + ss = savestr(vp->text); + p = strchr(ss, '='); *p = '\0'; - (void) setenv(vp->text, p + 1, 1); - *p = '='; + (void) setenv(ss, p + 1, 1); + ckfree(ss); (void) setlocale(LC_ALL, ""); } goto found; @@ -788,6 +791,7 @@ { struct var **vpp; struct var *vp; + char *ss, *eqp; vpp = hashvar(s); for (vp = *vpp ; vp ; vpp = &vp->next, vp = *vpp) { @@ -798,7 +802,11 @@ if (*(strchr(vp->text, '=') + 1) != '\0') setvar(s, nullstr, 0); if ((vp->flags & VEXPORT) && localevar(vp->text)) { - unsetenv(s); + ss = savestr(s); + if ((eqp = strchr(ss, '=')) != NULL) + *eqp = '\0'; + (void) unsetenv(ss); + ckfree(ss); setlocale(LC_ALL, ""); } vp->flags &= ~VEXPORT; -- http://ache.pp.ru/