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

From: Sean C. Farley <scf_at_FreeBSD.org>
Date: Sat, 14 Jul 2007 10:25:03 -0500 (CDT)
On Sat, 14 Jul 2007, Andrey Chernov wrote:

*snip*

> BTW, I fear about another place on this matter, merge_environ().
> Look at this example:
>
> ... some setenv's called before
>
> nenv[0] = NULL;
> environ = nenv;
> unsetenv("NONEXISTEN");
>
> What happens to environ pointer _after_ that?
>
> unsetenv() leads to environ = watchEnviron; in the merge_environ() but
> this environ is never rebuilded because no single setenv() is called
> from merge_environ() and no rebuild_environ() is called from
> unsetenv() due to "NONEXISTENT" value not found. It means reassigned
> environ inherits stale pointers from non-rebuilded watchEnviron which
> not equals to environ[0] == NULL
>
> Did I miss something?

No.  I see it too.  Here are the changes:
1. __merge_environ no longer touches environ.  Only __rebuild_environ(),
    __build_env() and __clean_env() alter environ.
2. watchEnviron renamed to intEnviron.
3. __rebuild_environ() uses intEnviron when cycling through the
    environment; it only sets environ.

This way environ is not changed unless it has at least one name-value
pair.

The new patch is here:
http://www.farley.org/freebsd/tmp/setenv/clearenv/patch2

Sean
-- 
scf_at_FreeBSD.org
Received on Sat Jul 14 2007 - 13:25:21 UTC

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