diff options
author | jilles <jilles@FreeBSD.org> | 2015-03-08 14:12:43 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2015-03-08 14:12:43 +0000 |
commit | 84c0730b384c7dbdfbb22c57d3b64272dde8da04 (patch) | |
tree | 9f7a757eed844aecbf8c6ad9ea8f2fbbbf2ecef9 | |
parent | a542258e7db83d5be1c791fbb0a8614f792bb6d6 (diff) | |
download | FreeBSD-src-84c0730b384c7dbdfbb22c57d3b64272dde8da04.zip FreeBSD-src-84c0730b384c7dbdfbb22c57d3b64272dde8da04.tar.gz |
env: Fix crash when -S string is not empty but no operand follows.
split_spaces() set argc in main() incorrectly, which caused trouble for
getopt().
Examples:
env -S '\c'
env -S -i
PR: 197769
MFC after: 1 week
-rw-r--r-- | tools/regression/usr.bin/env/regress-env.rgdata | 33 | ||||
-rw-r--r-- | tools/regression/usr.bin/env/regress-sb.rb | 1 | ||||
-rw-r--r-- | usr.bin/env/envopts.c | 4 |
3 files changed, 36 insertions, 2 deletions
diff --git a/tools/regression/usr.bin/env/regress-env.rgdata b/tools/regression/usr.bin/env/regress-env.rgdata index e060eac..90c296e 100644 --- a/tools/regression/usr.bin/env/regress-env.rgdata +++ b/tools/regression/usr.bin/env/regress-env.rgdata @@ -382,3 +382,36 @@ gblenv=OUTSIDEVAR=OutsideValue setenv:D=D_ThisisAlongstring_D1 stdout:A_ThisisAlongstring_A1 B_ThisisAlongstring_B1 C_ThisisAlongstring_C1 D_ThisisAlongstring_D1 ScriptName: [%-script.pathname-%] [run] + +[test] + sb_args:sh + script:[%-testpgm.pathname-%] -S '\c' >/dev/null +[run] +[test] + sb_args:sh + script:[%-testpgm.pathname-%] -S'\c' >/dev/null +[run] +[test] + sb_args:sh + script:[%-testpgm.pathname-%] -u foo -S '\c' >/dev/null +[run] +[test] + sb_args:sh + script:[%-testpgm.pathname-%] -u foo -S'\c' >/dev/null +[run] +[test] + sb_args:sh + script:[%-testpgm.pathname-%] -S '-u bar \c' >/dev/null +[run] +[test] + sb_args:sh + script:[%-testpgm.pathname-%] -S'-u bar \c' >/dev/null +[run] +[test] + sb_args:sh + script:[%-testpgm.pathname-%] -u foo -S '-u bar \c' >/dev/null +[run] +[test] + sb_args:sh + script:[%-testpgm.pathname-%] -u foo -S'-u bar \c' >/dev/null +[run] diff --git a/tools/regression/usr.bin/env/regress-sb.rb b/tools/regression/usr.bin/env/regress-sb.rb index f6333aa..b43ddd3 100644 --- a/tools/regression/usr.bin/env/regress-sb.rb +++ b/tools/regression/usr.bin/env/regress-sb.rb @@ -346,6 +346,7 @@ class RGTestOptions # "just anything" that matches the general pattern. There are # no blanks in the recognized values, but I use an x-tended # regexp and then add blanks to make it more readable. + optval.gsub!(/\[%- testpgm\.pathname -%\]/x, $testpgm) optval.gsub!(/\[%- testpgm\.basename -%\]/x, File.basename($testpgm)) optval.gsub!(/\[%- script\.pathname -%\]/x, $scriptfile) diff --git a/usr.bin/env/envopts.c b/usr.bin/env/envopts.c index f821430..5740062 100644 --- a/usr.bin/env/envopts.c +++ b/usr.bin/env/envopts.c @@ -372,9 +372,9 @@ str_done: *nextarg = NULL; /* Update optind/argc/argv in the calling routine */ - *origind = 1; - *origc += addcount; + *origc += addcount - *origind + 1; *origv = newargv; + *origind = 1; } /** |