Always copy the variable strings from environ to our variable structures in hush_main, instead of trying to share them.

This avoids problems stemming from the fact that GNO's environment implementation may deallocate those strings, in some cases before we're done with them. It also allows us to uppercase the variable names, although since we made them case-insensitive this only matters for display purposes (in "set" output).
This commit is contained in:
Stephen Heumann 2014-12-02 13:42:18 -06:00
parent 3805dfc06e
commit 81652ca9c4

View File

@ -8237,8 +8237,21 @@ int hush_main(int argc, char **argv)
if (value) { /* paranoia */ if (value) { /* paranoia */
cur_var->next = xzalloc(sizeof(*cur_var)); cur_var->next = xzalloc(sizeof(*cur_var));
cur_var = cur_var->next; cur_var = cur_var->next;
#ifndef __GNO__
cur_var->varstr = *e; cur_var->varstr = *e;
cur_var->max_len = strlen(*e); cur_var->max_len = strlen(*e);
#else
/* Don't try to use variable strings that are in the environment,
* because GNO's environ implementation manages them and may free
* them, which could cause problems for us. */
cur_var->varstr = xstrdup(*e);
cur_var->max_len = 0;
/* Uppercase environment variable names (which are lower-cased
* in environ), to match the usual convention. */
for (value = cur_var->varstr; *value != '='; ++value)
*value = toupper(*value);
#endif
cur_var->flg_export = 1; cur_var->flg_export = 1;
} }
e++; e++;