aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-11 02:37:48 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-11 02:37:48 +0200
commit9a7d0a01918df5a963b6c90177b321ff743282b2 (patch)
tree3378d6ce2ad70e7bc34423bd59ca49e5e9aa1304 /shell/hush.c
parent81f962f3df0d7194b7a52c6f83259727759094c4 (diff)
downloadbusybox-w32-9a7d0a01918df5a963b6c90177b321ff743282b2.tar.gz
busybox-w32-9a7d0a01918df5a963b6c90177b321ff743282b2.tar.bz2
busybox-w32-9a7d0a01918df5a963b6c90177b321ff743282b2.zip
shell: add OPTARG poisoning to getopt_optarg.tests
ash fails this! Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c
index f9a8de423..dc05f24b9 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -9872,7 +9872,8 @@ static int FAST_FUNC builtin_shift(char **argv)
9872#if ENABLE_HUSH_GETOPTS 9872#if ENABLE_HUSH_GETOPTS
9873static int FAST_FUNC builtin_getopts(char **argv) 9873static int FAST_FUNC builtin_getopts(char **argv)
9874{ 9874{
9875/* 9875/* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html
9876
9876TODO: 9877TODO:
9877If an invalid option is seen, getopts places ? into VAR and, if 9878If an invalid option is seen, getopts places ? into VAR and, if
9878not silent, prints an error message and unsets OPTARG. If 9879not silent, prints an error message and unsets OPTARG. If
@@ -9886,6 +9887,8 @@ colon (:) is placed in VAR and OPTARG is set to the option
9886character found. 9887character found.
9887 9888
9888Test that VAR is a valid variable name? 9889Test that VAR is a valid variable name?
9890
9891"Whenever the shell is invoked, OPTIND shall be initialized to 1"
9889*/ 9892*/
9890 char cbuf[2]; 9893 char cbuf[2];
9891 const char *cp, *optstring, *var; 9894 const char *cp, *optstring, *var;
@@ -9920,14 +9923,20 @@ Test that VAR is a valid variable name?
9920 exitcode = EXIT_FAILURE; 9923 exitcode = EXIT_FAILURE;
9921 c = '?'; 9924 c = '?';
9922 } 9925 }
9923 if (optarg)
9924 set_local_var_from_halves("OPTARG", optarg);
9925 else
9926 unset_local_var("OPTARG");
9927 cbuf[0] = c; 9926 cbuf[0] = c;
9928 cbuf[1] = '\0'; 9927 cbuf[1] = '\0';
9929 set_local_var_from_halves(var, cbuf); 9928 set_local_var_from_halves(var, cbuf);
9930 set_local_var_from_halves("OPTIND", utoa(optind)); 9929 set_local_var_from_halves("OPTIND", utoa(optind));
9930
9931 /* Always set or unset, never left as-is, even on exit/error:
9932 * "If no option was found, or if the option that was found
9933 * does not have an option-argument, OPTARG shall be unset."
9934 */
9935 if (optarg)
9936 set_local_var_from_halves("OPTARG", optarg);
9937 else
9938 unset_local_var("OPTARG");
9939
9931 return exitcode; 9940 return exitcode;
9932} 9941}
9933#endif 9942#endif