Re: Environment handling broken in /bin/sh with changes to {get,set,put}env()

From: Sean C. Farley <scf_at_FreeBSD.org>
Date: Sun, 8 Jul 2007 20:40:11 -0500 (CDT)
On Sun, 8 Jul 2007, Andrey Chernov wrote:

> On Sun, Jul 08, 2007 at 01:14:31PM -0500, Sean C. Farley wrote:

*snip*

>>> Could you please make setenv() wrapper like that to avoid modifying
>>> merged environ in the middle?
>>> 	__lsetenv(str, str_len, value)
>>
>> I could add this as a feature later.  Unfortunately, unless I can
>> lock the use of environ, an application could do this even with the
>> 6-STABLE version of *env() functions.  I have been pondering about
>> thread-safety in a future release of these functions (8-CURRENT), but
>> it may not be possible since environ is exposed.
>
> Even in case it may happens with 6-STABLE, we better not repeat the
> way lead to mistakes again :)

Your interpretation of the specification is correct.  My latest patch
should apply.  I changed getenv() to never change environ.  If it
detects that environ was replaced, it falls back to returning the value
from there.  Only setenv(), unsetenv() and putenv() will alter environ.
How does it look to you?

Sean
-- 
scf_at_FreeBSD.org
Received on Sun Jul 08 2007 - 23:40:33 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:14 UTC