summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-10-26 07:10:51 -0600
committerEric Blake <ebb9@byu.net>2009-10-26 21:30:30 -0600
commit243f1b1c71136171a4da635a84f8e32ba3eb3c94 (patch)
treeb3322fcf26a44e5b3f39479d89f58a34c4eab221 /src
parentc6900474ef4e0acc02bf5ff41c933afeef4aae09 (diff)
downloadcoreutils-243f1b1c71136171a4da635a84f8e32ba3eb3c94.tar.xz
env: reject bogus -u arguments
* src/env.c (main): Use unsetenv rather than putenv to remove items from environ, and check for failure. * bootstrap.conf (gnulib_modules): Add unsetenv. * tests/misc/env: Test this. * NEWS: Document it.
Diffstat (limited to 'src')
-rw-r--r--src/env.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/env.c b/src/env.c
index ee5e6b6ce..02d155d42 100644
--- a/src/env.c
+++ b/src/env.c
@@ -83,6 +83,7 @@
#include "system.h"
#include "error.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "env"
@@ -170,14 +171,19 @@ main (int argc, char **argv)
optind = 0; /* Force GNU getopt to re-initialize. */
while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)
- if (optc == 'u')
- putenv (optarg); /* Requires GNU putenv. */
+ if (optc == 'u' && unsetenv (optarg))
+ error (EXIT_CANCELED, errno, _("cannot unset %s"), quote (optarg));
if (optind < argc && STREQ (argv[optind], "-"))
++optind;
while (optind < argc && strchr (argv[optind], '='))
- putenv (argv[optind++]);
+ if (putenv (argv[optind++]))
+ {
+ char *name = argv[optind - 1];
+ *(strchr (name, '=')) = '\0';
+ error (EXIT_CANCELED, errno, _("cannot set %s"), quote (name));
+ }
/* If no program is specified, print the environment and exit. */
if (argc <= optind)