Environment handling broken in /bin/sh with changes to
t,set,put}env()
Sean C. Farley
scf at FreeBSD.org
Sat Jul 14 15:25:21 UTC 2007
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
More information about the freebsd-current
mailing list