svn commit: r279779 - in head: tools/regression/usr.bin/env usr.bin/env

Jilles Tjoelker jilles at FreeBSD.org
Sun Mar 8 14:12:45 UTC 2015


Author: jilles
Date: Sun Mar  8 14:12:43 2015
New Revision: 279779
URL: https://svnweb.freebsd.org/changeset/base/279779

Log:
  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

Modified:
  head/tools/regression/usr.bin/env/regress-env.rgdata
  head/tools/regression/usr.bin/env/regress-sb.rb
  head/usr.bin/env/envopts.c

Modified: head/tools/regression/usr.bin/env/regress-env.rgdata
==============================================================================
--- head/tools/regression/usr.bin/env/regress-env.rgdata	Sun Mar  8 13:52:07 2015	(r279778)
+++ head/tools/regression/usr.bin/env/regress-env.rgdata	Sun Mar  8 14:12:43 2015	(r279779)
@@ -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]

Modified: head/tools/regression/usr.bin/env/regress-sb.rb
==============================================================================
--- head/tools/regression/usr.bin/env/regress-sb.rb	Sun Mar  8 13:52:07 2015	(r279778)
+++ head/tools/regression/usr.bin/env/regress-sb.rb	Sun Mar  8 14:12:43 2015	(r279779)
@@ -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)
 

Modified: head/usr.bin/env/envopts.c
==============================================================================
--- head/usr.bin/env/envopts.c	Sun Mar  8 13:52:07 2015	(r279778)
+++ head/usr.bin/env/envopts.c	Sun Mar  8 14:12:43 2015	(r279779)
@@ -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;
 }
 
 /**


More information about the svn-src-head mailing list