aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shell/hush.c17
-rw-r--r--shell/hush_test/hush-vars/var_unbackslash.right20
-rwxr-xr-xshell/hush_test/hush-vars/var_unbackslash.tests6
3 files changed, 22 insertions, 21 deletions
diff --git a/shell/hush.c b/shell/hush.c
index b19d4ea01..d58f526b8 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3525,16 +3525,15 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign
3525 3525
3526/* Return code: 0 for OK, 1 for syntax error */ 3526/* Return code: 0 for OK, 1 for syntax error */
3527#if BB_MMU 3527#if BB_MMU
3528#define parse_dollar(as_string, dest, input) \ 3528#define parse_dollar(as_string, dest, input, quote_mask) \
3529 parse_dollar(dest, input) 3529 parse_dollar(dest, input, quote_mask)
3530#define as_string NULL 3530#define as_string NULL
3531#endif 3531#endif
3532static int parse_dollar(o_string *as_string, 3532static int parse_dollar(o_string *as_string,
3533 o_string *dest, 3533 o_string *dest,
3534 struct in_str *input) 3534 struct in_str *input, unsigned char quote_mask)
3535{ 3535{
3536 int ch = i_peek(input); /* first character after the $ */ 3536 int ch = i_peek(input); /* first character after the $ */
3537 unsigned char quote_mask = (dest->o_expflags & EXP_FLAG_ESC_GLOB_CHARS) ? 0x80 : 0;
3538 3537
3539 debug_printf_parse("parse_dollar entered: ch='%c'\n", ch); 3538 debug_printf_parse("parse_dollar entered: ch='%c'\n", ch);
3540 if (isalpha(ch)) { 3539 if (isalpha(ch)) {
@@ -3576,17 +3575,19 @@ static int parse_dollar(o_string *as_string,
3576 nommu_addchr(as_string, ch); 3575 nommu_addchr(as_string, ch);
3577 3576
3578 ch = i_getch(input); /* first char after '{' */ 3577 ch = i_getch(input); /* first char after '{' */
3579 nommu_addchr(as_string, ch);
3580 /* It should be ${?}, or ${#var}, 3578 /* It should be ${?}, or ${#var},
3581 * or even ${?+subst} - operator acting on a special variable, 3579 * or even ${?+subst} - operator acting on a special variable,
3582 * or the beginning of variable name. 3580 * or the beginning of variable name.
3583 */ 3581 */
3584 if (!strchr(_SPECIAL_VARS_STR, ch) && !isalnum(ch)) { /* not one of those */ 3582 if (ch == EOF
3583 || (!strchr(_SPECIAL_VARS_STR, ch) && !isalnum(ch)) /* not one of those */
3584 ) {
3585 bad_dollar_syntax: 3585 bad_dollar_syntax:
3586 syntax_error_unterm_str("${name}"); 3586 syntax_error_unterm_str("${name}");
3587 debug_printf_parse("parse_dollar return 1: unterminated ${name}\n"); 3587 debug_printf_parse("parse_dollar return 1: unterminated ${name}\n");
3588 return 1; 3588 return 1;
3589 } 3589 }
3590 nommu_addchr(as_string, ch);
3590 ch |= quote_mask; 3591 ch |= quote_mask;
3591 3592
3592 /* It's possible to just call add_till_closing_bracket() at this point. 3593 /* It's possible to just call add_till_closing_bracket() at this point.
@@ -3785,7 +3786,7 @@ static int parse_stream_dquoted(o_string *as_string,
3785 goto again; 3786 goto again;
3786 } 3787 }
3787 if (ch == '$') { 3788 if (ch == '$') {
3788 if (parse_dollar(as_string, dest, input) != 0) { 3789 if (parse_dollar(as_string, dest, input, /*quote_mask:*/ 0x80) != 0) {
3789 debug_printf_parse("parse_stream_dquoted return 1: " 3790 debug_printf_parse("parse_stream_dquoted return 1: "
3790 "parse_dollar returned non-0\n"); 3791 "parse_dollar returned non-0\n");
3791 return 1; 3792 return 1;
@@ -4135,7 +4136,7 @@ static struct pipe *parse_stream(char **pstring,
4135#endif 4136#endif
4136 break; 4137 break;
4137 case '$': 4138 case '$':
4138 if (parse_dollar(&ctx.as_string, &dest, input) != 0) { 4139 if (parse_dollar(&ctx.as_string, &dest, input, /*quote_mask:*/ 0) != 0) {
4139 debug_printf_parse("parse_stream parse error: " 4140 debug_printf_parse("parse_stream parse error: "
4140 "parse_dollar returned non-0\n"); 4141 "parse_dollar returned non-0\n");
4141 goto parse_error; 4142 goto parse_error;
diff --git a/shell/hush_test/hush-vars/var_unbackslash.right b/shell/hush_test/hush-vars/var_unbackslash.right
index 20c2ddf55..8bc834711 100644
--- a/shell/hush_test/hush-vars/var_unbackslash.right
+++ b/shell/hush_test/hush-vars/var_unbackslash.right
@@ -1,11 +1,11 @@
1b1=-qwerty-t-\-"---z-*-?- 1b1=-qwerty-t-\-"-`---z-*-?-
2b1=-qwerty-t-\-"---z-*-?- 2b1=-qwerty-t-\-"-`---z-*-?-
3b2=-qwerty-\t-\-"-\--\z-\*-\?- 3b2=-qwerty-\t-\-"-`-\--\z-\*-\?-
4b2=-qwerty-\t-\-"-\--\z-\*-\?- 4b2=-qwerty-\t-\-"-`-\--\z-\*-\?-
5b3=-$a-\t-\\-\"-\--\z-\*-\?- 5b3=-$a-\t-\\-\"-\`-\--\z-\*-\?-
6b3=-$a-\t-\\-\"-\--\z-\*-\?- 6b3=-$a-\t-\\-\"-\`-\--\z-\*-\?-
7c=-$a-\t-\\-\"-\--\z-\*-\?- 7c=-$a-\t-\\-\"-\`-\--\z-\*-\?-
8c=-$a-\t-\\-\"-\--\z-\*-\?- 8c=-$a-\t-\\-\"-\`-\--\z-\*-\?-
9c=-$a-\t-\\-\"-\--\z-\*-\?- 9c=-$a-\t-\\-\"-\`-\--\z-\*-\?-
10c=-$a-\t-\\-\"-\--\z-\*-\?- 10c=-$a-\t-\\-\"-\`-\--\z-\*-\?-
11Done: 0 11Done: 0
diff --git a/shell/hush_test/hush-vars/var_unbackslash.tests b/shell/hush_test/hush-vars/var_unbackslash.tests
index 3c35d7df5..bb52af3d0 100755
--- a/shell/hush_test/hush-vars/var_unbackslash.tests
+++ b/shell/hush_test/hush-vars/var_unbackslash.tests
@@ -1,13 +1,13 @@
1# Test for correct handling of backslashes 1# Test for correct handling of backslashes
2a=qwerty 2a=qwerty
3 3
4b=-$a-\t-\\-\"-\--\z-\*-\?- 4b=-$a-\t-\\-\"-\`-\--\z-\*-\?-
5echo b1=$b 5echo b1=$b
6echo "b1=$b" 6echo "b1=$b"
7b="-$a-\t-\\-\"-\--\z-\*-\?-" 7b="-$a-\t-\\-\"-\`-\--\z-\*-\?-"
8echo b2=$b 8echo b2=$b
9echo "b2=$b" 9echo "b2=$b"
10b='-$a-\t-\\-\"-\--\z-\*-\?-' 10b='-$a-\t-\\-\"-\`-\--\z-\*-\?-'
11echo b3=$b 11echo b3=$b
12echo "b3=$b" 12echo "b3=$b"
13 13