diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-20 17:36:06 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-20 17:36:06 +0200 |
commit | 83e434d5b56baccf617ebcc8a752959f7c4aacfc (patch) | |
tree | 46a311ce40ba3f2e444d6cbf0c306351393498bf /shell/hush.c | |
parent | 294eb4612cd668521faa48711297196f00af61d9 (diff) | |
download | busybox-w32-83e434d5b56baccf617ebcc8a752959f7c4aacfc.tar.gz busybox-w32-83e434d5b56baccf617ebcc8a752959f7c4aacfc.tar.bz2 busybox-w32-83e434d5b56baccf617ebcc8a752959f7c4aacfc.zip |
hush: fix handling of '' in ${var:+ARG}
This wasn't an ash bug in dollar_altvalue9, it was hush bug (and bash!)
function old new delta
expand_one_var 2236 2254 +18
expand_vars_to_list 1097 1103 +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 24/0) Total: 24 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/shell/hush.c b/shell/hush.c index fc77b89fc..559595d2e 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -475,7 +475,6 @@ | |||
475 | #endif | 475 | #endif |
476 | 476 | ||
477 | #define SPECIAL_VAR_SYMBOL_STR "\3" | 477 | #define SPECIAL_VAR_SYMBOL_STR "\3" |
478 | #define SPECIAL_VAR_SYMBOL_CHR '\3' | ||
479 | #define SPECIAL_VAR_SYMBOL 3 | 478 | #define SPECIAL_VAR_SYMBOL 3 |
480 | /* The "variable" with name "\1" emits string "\3". Testcase: "echo ^C" */ | 479 | /* The "variable" with name "\1" emits string "\3". Testcase: "echo ^C" */ |
481 | #define SPECIAL_VAR_QUOTED_SVS 1 | 480 | #define SPECIAL_VAR_QUOTED_SVS 1 |
@@ -5950,6 +5949,8 @@ static int encode_then_append_var_plusminus(o_string *output, int n, | |||
5950 | break; | 5949 | break; |
5951 | o_addqchr(&dest, ch); | 5950 | o_addqchr(&dest, ch); |
5952 | } | 5951 | } |
5952 | o_addchr(&dest, SPECIAL_VAR_SYMBOL); | ||
5953 | o_addchr(&dest, SPECIAL_VAR_SYMBOL); | ||
5953 | continue; | 5954 | continue; |
5954 | } | 5955 | } |
5955 | } | 5956 | } |
@@ -5959,6 +5960,10 @@ static int encode_then_append_var_plusminus(o_string *output, int n, | |||
5959 | } | 5960 | } |
5960 | if (ch == '"') { | 5961 | if (ch == '"') { |
5961 | dest.o_expflags ^= EXP_FLAG_ESC_GLOB_CHARS; | 5962 | dest.o_expflags ^= EXP_FLAG_ESC_GLOB_CHARS; |
5963 | if (dest.o_expflags) { | ||
5964 | o_addchr(&dest, SPECIAL_VAR_SYMBOL); | ||
5965 | o_addchr(&dest, SPECIAL_VAR_SYMBOL); | ||
5966 | } | ||
5962 | continue; | 5967 | continue; |
5963 | } | 5968 | } |
5964 | if (ch == '\\') { | 5969 | if (ch == '\\') { |
@@ -6565,7 +6570,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg) | |||
6565 | case SPECIAL_VAR_QUOTED_SVS: | 6570 | case SPECIAL_VAR_QUOTED_SVS: |
6566 | /* <SPECIAL_VAR_SYMBOL><SPECIAL_VAR_QUOTED_SVS><SPECIAL_VAR_SYMBOL> */ | 6571 | /* <SPECIAL_VAR_SYMBOL><SPECIAL_VAR_QUOTED_SVS><SPECIAL_VAR_SYMBOL> */ |
6567 | /* "^C variable", represents literal ^C char (possible in scripts) */ | 6572 | /* "^C variable", represents literal ^C char (possible in scripts) */ |
6568 | o_addchr(output, SPECIAL_VAR_SYMBOL_CHR); | 6573 | o_addchr(output, SPECIAL_VAR_SYMBOL); |
6569 | arg++; | 6574 | arg++; |
6570 | break; | 6575 | break; |
6571 | #if ENABLE_HUSH_TICK | 6576 | #if ENABLE_HUSH_TICK |
@@ -6627,7 +6632,8 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg) | |||
6627 | o_addstr(output, arg); | 6632 | o_addstr(output, arg); |
6628 | debug_print_list("expand_vars_to_list[b]", output, n); | 6633 | debug_print_list("expand_vars_to_list[b]", output, n); |
6629 | } else if (output->length == o_get_last_ptr(output, n) /* expansion is empty */ | 6634 | } else if (output->length == o_get_last_ptr(output, n) /* expansion is empty */ |
6630 | && !(cant_be_null & 0x80) /* and all vars were not quoted. */ | 6635 | && !(cant_be_null & 0x80) /* and all vars were not quoted */ |
6636 | && !output->has_quoted_part | ||
6631 | ) { | 6637 | ) { |
6632 | n--; | 6638 | n--; |
6633 | /* allow to reuse list[n] later without re-growth */ | 6639 | /* allow to reuse list[n] later without re-growth */ |