aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-12 14:52:47 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-12 14:52:47 +0100
commitf4fee418ae9f5308b4d32bc8d4e618f779f3203f (patch)
treea8c10ec6f1513f928d04d3e5c8983754804fe330 /coreutils
parentab19ede65595f6c0daba1e9b6c7c0a2ede341fec (diff)
downloadbusybox-w32-f4fee418ae9f5308b4d32bc8d4e618f779f3203f.tar.gz
busybox-w32-f4fee418ae9f5308b4d32bc8d4e618f779f3203f.tar.bz2
busybox-w32-f4fee418ae9f5308b4d32bc8d4e618f779f3203f.zip
env: don't SEGV on bare "env -"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/env.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/coreutils/env.c b/coreutils/env.c
index f50a03e8b..9635d2b22 100644
--- a/coreutils/env.c
+++ b/coreutils/env.c
@@ -43,21 +43,20 @@ static const char env_longopts[] ALIGN1 =
43int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 43int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
44int env_main(int argc UNUSED_PARAM, char **argv) 44int env_main(int argc UNUSED_PARAM, char **argv)
45{ 45{
46 char **ep; 46 unsigned opts;
47 unsigned opt;
48 llist_t *unset_env = NULL; 47 llist_t *unset_env = NULL;
49 48
50 opt_complementary = "u::"; 49 opt_complementary = "u::";
51#if ENABLE_FEATURE_ENV_LONG_OPTIONS 50#if ENABLE_FEATURE_ENV_LONG_OPTIONS
52 applet_long_options = env_longopts; 51 applet_long_options = env_longopts;
53#endif 52#endif
54 opt = getopt32(argv, "+iu:", &unset_env); 53 opts = getopt32(argv, "+iu:", &unset_env);
55 argv += optind; 54 argv += optind;
56 if (*argv && LONE_DASH(argv[0])) { 55 if (argv[0] && LONE_DASH(argv[0])) {
57 opt |= 1; 56 opts |= 1;
58 ++argv; 57 ++argv;
59 } 58 }
60 if (opt & 1) { 59 if (opts & 1) {
61 clearenv(); 60 clearenv();
62 } 61 }
63 while (unset_env) { 62 while (unset_env) {
@@ -84,8 +83,11 @@ int env_main(int argc UNUSED_PARAM, char **argv)
84 bb_simple_perror_msg_and_die(*argv); 83 bb_simple_perror_msg_and_die(*argv);
85 } 84 }
86 85
87 for (ep = environ; *ep; ep++) { 86 if (environ) { /* clearenv() may set environ == NULL! */
88 puts(*ep); 87 char **ep;
88 for (ep = environ; *ep; ep++) {
89 puts(*ep);
90 }
89 } 91 }
90 92
91 fflush_stdout_and_exit(EXIT_SUCCESS); 93 fflush_stdout_and_exit(EXIT_SUCCESS);