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

Crash when exporting scalar without value and getsparam fails



2086                if (!(pm->node.flags & PM_UNSET) && !pm->env && !value)

30. returned_null: getsparam returns null (checked 46 out of 57
times). [show details]

CID 439066 (#1 of 1): Dereference null return value (NULL_RETURNS)31.
dereference: Dereferencing a pointer that might be null
getsparam(pname) when calling addenv. [show details]
2087                    addenv(pm, getsparam(pname));


The issue has this comment by Oliver on it, but I couldn't find any
thread about it with a cursory search, so I'm repeating it here;

Comment:

The line of code occurs when you export an existing scalar variable
without giving a new value. It isn't easy to find ways of making
getsparam to fail but I've found one which is enough to declare this a
bug:
 unset IFS
 export IFS
memory allocation failing, such as dupstring would also do the job.
Arguably these cases need fixing but the code highlighted here should
perhaps default to adding the variable to the environment with an
empty value.


and sure enough,
zsh: segmentation fault (core dumped)  zsh -fc 'unset IFS; export IFS'

Would the non-gnu equivalent of addenv(pm, getsparam(pname) ?: ""); do
the trick here? Or should it just return with an error? I guess if we
do the former, then the environment would get out of sync with the
internal parameter value.

-- 
Mikael Magnusson



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