diff options
author | Eric Blake <ebb9@byu.net> | 2009-10-26 07:10:51 -0600 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2009-10-26 21:30:30 -0600 |
commit | 243f1b1c71136171a4da635a84f8e32ba3eb3c94 (patch) | |
tree | b3322fcf26a44e5b3f39479d89f58a34c4eab221 /src | |
parent | c6900474ef4e0acc02bf5ff41c933afeef4aae09 (diff) | |
download | coreutils-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.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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) |