In running bash on an embedded target, bash crashes for the silly
reason that environ is NULL.

I haven't been able to tell whether this is actually permitted by the
standard (as if?), but in bash I think this behavior is inconsistent
anyway because:

   * in initialize_shell_variables() from variables.c on line 344 the
"env == NULL" case is guarded against, while
   * in getenv() from lib/sh/getenv.c on line 81 access to environ is
performed unprotected.

Attached below is the tiny modification required to prevent the
segfault which occurs in the latter case. Of course, the extra
condition is only checked when "shell_variables == NULL", which is
true only before initialization has been completed. Would you consider
the addition of this protection at all acceptable?

Kind regards,
Keeley Hoek

diff --git a/lib/sh/getenv.c b/lib/sh/getenv.c
index 8b5e3406..1e682aef 100644
--- a/lib/sh/getenv.c
+++ b/lib/sh/getenv.c
@@ -69,7 +69,7 @@ getenv (name)
       if (var && exported_p (var))
        return (value_cell (var));
     }
-  else
+  else if (environ)
     {
       register int i, len;

Reply via email to