Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] mkenvstr: avoid crash in case NULL is given as value



On Tuesday 19 May 2015 16:12:22 Bart Schaefer wrote:
> Is it really safe to return NULL from mkenvstr()?  The places where it
> is called would seem to imply not, e.g. here ...
> 
>                     if (pm->node.flags & PM_SPECIAL)
>                         pm->env = mkenvstr (pm->node.nam,
>                                             getsparam(pm->node.nam),
> pm->node.flags); else
>                         pm->env = ztrdup(*envp2);
> #ifndef USE_SET_UNSET_ENV
>                     *envp++ = pm->env;
> #endif
> 
> ... you'd get a spurious NULL in envp, and here ...
> 
>      newenv = mkenvstr(pm->node.nam, value, pm->node.flags);
>      if (zputenv(newenv)) {
> 
> ... you'd get an error from zputenv():
> 
>     DPUTS(!str, "Attempt to put null string into environment.");

Good catch!  Then your patch certainly looks as a better choice to me.

Kamil



Messages sorted by: Reverse Date, Date, Thread, Author