From owner-freebsd-current@FreeBSD.ORG Sat Jul 14 00:41:18 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 85F7E16A408; Sat, 14 Jul 2007 00:41:18 +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 C7F9413C4B4; Sat, 14 Jul 2007 00:41:17 +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 l6E0fGqY024183; Sat, 14 Jul 2007 04:41:16 +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=1184373676; bh=bRnb1AfSPGA156CnZAa0VoS8l4axw0Ey8W5Qrso N9Lk=; l=1234; h=Received:Date:From:To:Cc:Subject:Message-ID: Mail-Followup-To:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:User-Agent; b=Ie4uenIJxyv3ErGep0h0 v6VfaQI1+SWKfIrSUBMA6+tJRndC4g8XPUgDEweKVw0Y37H7pRXv6Mda0KoEbDmHaNT cRR2tqFcWpPB+I5c1/VThS0uz8kg89j2OXj38AHN3tiETB33NRw0fUfc1kXU1LjC5HH j7WN2M71XgauHHlRQ= Received: (from ache@localhost) by nagual.pp.ru (8.14.1/8.14.1/Submit) id l6E0fGW9024182; Sat, 14 Jul 2007 04:41:16 +0400 (MSD) (envelope-from ache) Date: Sat, 14 Jul 2007 04:41:16 +0400 From: Andrey Chernov To: "Sean C. Farley" Message-ID: <20070714004116.GA22909@nagual.pp.ru> Mail-Followup-To: Andrey Chernov , "Sean C. Farley" , freebsd-current References: <20070707205410.B14065@thor.farley.org> <20070708020940.GA80166@nagual.pp.ru> <20070708171727.GA90490@nagual.pp.ru> <20070713162742.GA16260@nagual.pp.ru> <20070713142545.K26096@thor.farley.org> <20070713202433.GA19856@nagual.pp.ru> <20070713203915.GA20270@nagual.pp.ru> <20070713171942.Q26096@thor.farley.org> <20070713224608.GB21695@nagual.pp.ru> <20070713184543.A26096@thor.farley.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070713184543.A26096@thor.farley.org> User-Agent: Mutt/1.5.16 (2007-06-09) Cc: freebsd-current Subject: Re: Environment handling broken in /bin/sh with changes to t,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: Sat, 14 Jul 2007 00:41:18 -0000 On Fri, Jul 13, 2007 at 07:08:37PM -0500, Sean C. Farley wrote: > different. Are you saying that the addresses should not change for > environ, environ[0-1] or all? I try to say that *env() functions should avoid to change memory they not "own" when it is possible and feel free to change the memory they "own". What standard says is that initial copying all environ to the internal structure and changing it afterwards (exluding putenv case) is the right thing (because *env() functions "owns" that memory). To avoid even things like nenv[0] = "PATH=/bin"; setenv("PATH", "/bin", 1); fails, better way is to strdup() (i.e. copying) every string from the original environ and you already do that initially in build_env() but not do the safe way in previous merge_environ(). BTW, I find that code in build_env() very suspicious: if (environ[0] == NULL) goto SaveEnviron; ... SaveEnviron: origEnviron = environ; environ = NULL; if (envVarsTotal > 0) { ... } else rtrnVal = 0; return (rtrnVal); It ends up with environ = NULL; because envVarsTotal initialized to 0 i.e. makes from "environ[0] == NULL" case "environ == NULL" case which is different thing. -- http://ache.pp.ru/