mirror of
https://github.com/sheumann/hush.git
synced 2025-01-04 22:34:37 +00:00
fix globbing in unquoted $* and $@
This commit is contained in:
parent
4a689e9b49
commit
324a3fdf87
17
shell/hush.c
17
shell/hush.c
@ -342,6 +342,8 @@ typedef struct {
|
|||||||
char *data;
|
char *data;
|
||||||
int length;
|
int length;
|
||||||
int maxlen;
|
int maxlen;
|
||||||
|
/* Misnomer! it's not "quoting", it's "protection against globbing"!
|
||||||
|
* (by prepending \ to *, ?, [ and to \ too) */
|
||||||
smallint o_quote;
|
smallint o_quote;
|
||||||
smallint o_glob;
|
smallint o_glob;
|
||||||
smallint nonnull;
|
smallint nonnull;
|
||||||
@ -2398,8 +2400,10 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
|
|||||||
if (!global_argv[i])
|
if (!global_argv[i])
|
||||||
break;
|
break;
|
||||||
if (!(first_ch & 0x80)) { /* unquoted $* or $@ */
|
if (!(first_ch & 0x80)) { /* unquoted $* or $@ */
|
||||||
|
smallint sv = output->o_quote;
|
||||||
|
/* unquoted var's contents should be globbed, so don't quote */
|
||||||
|
output->o_quote = 0;
|
||||||
while (global_argv[i]) {
|
while (global_argv[i]) {
|
||||||
//see expand_on_ifs below - same??
|
|
||||||
n = expand_on_ifs(output, n, global_argv[i]);
|
n = expand_on_ifs(output, n, global_argv[i]);
|
||||||
debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, global_argc-1);
|
debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, global_argc-1);
|
||||||
if (global_argv[i++][0] && global_argv[i]) {
|
if (global_argv[i++][0] && global_argv[i]) {
|
||||||
@ -2411,12 +2415,13 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
|
|||||||
debug_print_list("expand_vars_to_list[3]", output, n);
|
debug_print_list("expand_vars_to_list[3]", output, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
output->o_quote = sv;
|
||||||
} else
|
} else
|
||||||
/* If or_mask is nonzero, we handle assignment 'a=....$@.....'
|
/* If or_mask is nonzero, we handle assignment 'a=....$@.....'
|
||||||
* and in this case should treat it like '$*' - see 'else...' below */
|
* and in this case should treat it like '$*' - see 'else...' below */
|
||||||
if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */
|
if (first_ch == ('@'|0x80) && !or_mask) { /* quoted $@ */
|
||||||
while (1) {
|
while (1) {
|
||||||
o_addQstr(output, global_argv[i], strlen(global_argv[i])); ///really Q?
|
o_addQstr(output, global_argv[i], strlen(global_argv[i]));
|
||||||
if (++i >= global_argc)
|
if (++i >= global_argc)
|
||||||
break;
|
break;
|
||||||
o_addchr(output, '\0');
|
o_addchr(output, '\0');
|
||||||
@ -2425,7 +2430,7 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
|
|||||||
}
|
}
|
||||||
} else { /* quoted $*: add as one word */
|
} else { /* quoted $*: add as one word */
|
||||||
while (1) {
|
while (1) {
|
||||||
o_addQstr(output, global_argv[i], strlen(global_argv[i])); ///really Q?
|
o_addQstr(output, global_argv[i], strlen(global_argv[i]));
|
||||||
if (!global_argv[++i])
|
if (!global_argv[++i])
|
||||||
break;
|
break;
|
||||||
if (ifs[0])
|
if (ifs[0])
|
||||||
@ -2482,7 +2487,7 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val) {
|
if (val) {
|
||||||
o_addQstr(output, val, strlen(val)); ///maybe q?
|
o_addQstr(output, val, strlen(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_HUSH_TICK
|
#if ENABLE_HUSH_TICK
|
||||||
@ -2517,8 +2522,8 @@ static char **expand_variables(char **argv, int or_mask)
|
|||||||
o_string output = NULL_O_STRING;
|
o_string output = NULL_O_STRING;
|
||||||
|
|
||||||
if (or_mask & 0x100) {
|
if (or_mask & 0x100) {
|
||||||
output.o_quote = 1;
|
output.o_quote = 1; /* protect against globbing for "$var" */
|
||||||
/* why? */
|
/* (unquoted $var will temporarily switch it off) */
|
||||||
output.o_glob = 1;
|
output.o_glob = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
shell/hush_test/hush-vars/param_glob.right
Normal file
4
shell/hush_test/hush-vars/param_glob.right
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
param_glob.tests
|
||||||
|
param_glob.tests
|
||||||
|
param_glob.t*
|
||||||
|
param_glob.t*
|
10
shell/hush_test/hush-vars/param_glob.tests
Executable file
10
shell/hush_test/hush-vars/param_glob.tests
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
if test $# = 0; then
|
||||||
|
#BUG in builtin_exec! will glob param!
|
||||||
|
#exec "$THIS_SH" "$0" 'param_glob.t*'
|
||||||
|
"$THIS_SH" "$0" 'param_glob.t*'
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
echo $*
|
||||||
|
echo $@
|
||||||
|
echo "$*"
|
||||||
|
echo "$@"
|
Loading…
Reference in New Issue
Block a user