diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-03-08 12:44:02 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-03-08 12:44:02 +0100 |
commit | 86cf0364bd58e07646a23a1128e4a9ea79189579 (patch) | |
tree | 22e161a76936796b5f8d49536684d371e7e8bfc3 /coreutils | |
parent | 6b6af53426d98ab513972bd710f250e246e7fc98 (diff) | |
download | busybox-w32-86cf0364bd58e07646a23a1128e4a9ea79189579.tar.gz busybox-w32-86cf0364bd58e07646a23a1128e4a9ea79189579.tar.bz2 busybox-w32-86cf0364bd58e07646a23a1128e4a9ea79189579.zip |
printenv: fix environ == NULL segfault
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/printenv.c | 11 | ||||
-rw-r--r-- | coreutils/test.c | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/coreutils/printenv.c b/coreutils/printenv.c index 33be5c096..d0fb71636 100644 --- a/coreutils/printenv.c +++ b/coreutils/printenv.c | |||
@@ -19,9 +19,14 @@ int printenv_main(int argc UNUSED_PARAM, char **argv) | |||
19 | 19 | ||
20 | /* no variables specified, show whole env */ | 20 | /* no variables specified, show whole env */ |
21 | if (!argv[1]) { | 21 | if (!argv[1]) { |
22 | int e = 0; | 22 | char **e = environ; |
23 | while (environ[e]) | 23 | |
24 | puts(environ[e++]); | 24 | /* environ can be NULL! (for example, after clearenv()) |
25 | * Check for that: | ||
26 | */ | ||
27 | if (e) | ||
28 | while (*e) | ||
29 | puts(*e++); | ||
25 | } else { | 30 | } else { |
26 | /* search for specified variables and print them out if found */ | 31 | /* search for specified variables and print them out if found */ |
27 | char *arg, *env; | 32 | char *arg, *env; |
diff --git a/coreutils/test.c b/coreutils/test.c index 8248a1ef5..2d245be6c 100644 --- a/coreutils/test.c +++ b/coreutils/test.c | |||
@@ -45,7 +45,7 @@ | |||
45 | /* This is a NOFORK applet. Be very careful! */ | 45 | /* This is a NOFORK applet. Be very careful! */ |
46 | 46 | ||
47 | /* test_main() is called from shells, and we need to be extra careful here. | 47 | /* test_main() is called from shells, and we need to be extra careful here. |
48 | * This is true regardless of PREFER_APPLETS and STANDALONE_SHELL | 48 | * This is true regardless of PREFER_APPLETS and SH_STANDALONE |
49 | * state. */ | 49 | * state. */ |
50 | 50 | ||
51 | /* test(1) accepts the following grammar: | 51 | /* test(1) accepts the following grammar: |