summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-03-08 11:44:02 (GMT)
committer Denys Vlasenko <vda.linux@googlemail.com>2011-03-08 11:44:02 (GMT)
commit86cf0364bd58e07646a23a1128e4a9ea79189579 (patch)
tree22e161a76936796b5f8d49536684d371e7e8bfc3
parent6b6af53426d98ab513972bd710f250e246e7fc98 (diff)
downloadbusybox-86cf0364bd58e07646a23a1128e4a9ea79189579.tar.gz
busybox-86cf0364bd58e07646a23a1128e4a9ea79189579.tar.bz2
printenv: fix environ == NULL segfault
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/printenv.c11
-rw-r--r--coreutils/test.c2
2 files changed, 9 insertions, 4 deletions
diff --git a/coreutils/printenv.c b/coreutils/printenv.c
index 33be5c0..d0fb716 100644
--- a/coreutils/printenv.c
+++ b/coreutils/printenv.c
@@ -19,9 +19,14 @@ int printenv_main(int argc UNUSED_PARAM, char **argv)
/* no variables specified, show whole env */
if (!argv[1]) {
- int e = 0;
- while (environ[e])
- puts(environ[e++]);
+ char **e = environ;
+
+ /* environ can be NULL! (for example, after clearenv())
+ * Check for that:
+ */
+ if (e)
+ while (*e)
+ puts(*e++);
} else {
/* search for specified variables and print them out if found */
char *arg, *env;
diff --git a/coreutils/test.c b/coreutils/test.c
index 8248a1e..2d245be 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -45,7 +45,7 @@
/* This is a NOFORK applet. Be very careful! */
/* test_main() is called from shells, and we need to be extra careful here.
- * This is true regardless of PREFER_APPLETS and STANDALONE_SHELL
+ * This is true regardless of PREFER_APPLETS and SH_STANDALONE
* state. */
/* test(1) accepts the following grammar: