Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14299 > unrolled thread

[PATCH] Fix null environ crash in getenv() provided by lib/sh/getenv.c

Started byKeeley Hoek <keeley@hoek.io>
First post2018-07-08 21:21 +1000
Last post2018-07-08 21:21 +1000
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug


Contents

  [PATCH] Fix null environ crash in getenv() provided by lib/sh/getenv.c Keeley Hoek <keeley@hoek.io> - 2018-07-08 21:21 +1000

#14299 — [PATCH] Fix null environ crash in getenv() provided by lib/sh/getenv.c

FromKeeley Hoek <keeley@hoek.io>
Date2018-07-08 21:21 +1000
Subject[PATCH] Fix null environ crash in getenv() provided by lib/sh/getenv.c
Message-ID<mailman.3251.1531054800.1292.bug-bash@gnu.org>
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;

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web