diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-09 14:04:57 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-09 14:04:57 +0200 |
commit | 101a4e3e2170e5ffa2bd2b06d7a71088a0ab8958 (patch) | |
tree | 308531a1fe9fcd7e6a5503e97a99465c9b8d5b1c /shell | |
parent | 5b6210cf492dba4474d83a138c95b1267777826b (diff) | |
download | busybox-101a4e3e2170e5ffa2bd2b06d7a71088a0ab8958.tar.gz |
hush: make parse_dollar flag quited status regardless of glob escaping status
function old new delta
parse_stream_dquoted 228 233 +5
parse_stream 2369 2371 +2
parse_dollar 730 717 -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 7/-13) Total: -6 bytes
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 17 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/var_unbackslash.right | 20 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/var_unbackslash.tests | 6 |
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 /* Return code: 0 for OK, 1 for syntax error */ #if BB_MMU -#define parse_dollar(as_string, dest, input) \ - parse_dollar(dest, input) +#define parse_dollar(as_string, dest, input, quote_mask) \ + parse_dollar(dest, input, quote_mask) #define as_string NULL #endif static int parse_dollar(o_string *as_string, o_string *dest, - struct in_str *input) + struct in_str *input, unsigned char quote_mask) { int ch = i_peek(input); /* first character after the $ */ - unsigned char quote_mask = (dest->o_expflags & EXP_FLAG_ESC_GLOB_CHARS) ? 0x80 : 0; debug_printf_parse("parse_dollar entered: ch='%c'\n", ch); if (isalpha(ch)) { @@ -3576,17 +3575,19 @@ static int parse_dollar(o_string *as_string, nommu_addchr(as_string, ch); ch = i_getch(input); /* first char after '{' */ - nommu_addchr(as_string, ch); /* It should be ${?}, or ${#var}, * or even ${?+subst} - operator acting on a special variable, * or the beginning of variable name. */ - if (!strchr(_SPECIAL_VARS_STR, ch) && !isalnum(ch)) { /* not one of those */ + if (ch == EOF + || (!strchr(_SPECIAL_VARS_STR, ch) && !isalnum(ch)) /* not one of those */ + ) { bad_dollar_syntax: syntax_error_unterm_str("${name}"); debug_printf_parse("parse_dollar return 1: unterminated ${name}\n"); return 1; } + nommu_addchr(as_string, ch); ch |= quote_mask; /* 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, goto again; } if (ch == '$') { - if (parse_dollar(as_string, dest, input) != 0) { + if (parse_dollar(as_string, dest, input, /*quote_mask:*/ 0x80) != 0) { debug_printf_parse("parse_stream_dquoted return 1: " "parse_dollar returned non-0\n"); return 1; @@ -4135,7 +4136,7 @@ static struct pipe *parse_stream(char **pstring, #endif break; case '$': - if (parse_dollar(&ctx.as_string, &dest, input) != 0) { + if (parse_dollar(&ctx.as_string, &dest, input, /*quote_mask:*/ 0) != 0) { debug_printf_parse("parse_stream parse error: " "parse_dollar returned non-0\n"); 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 @@ -b1=-qwerty-t-\-"---z-*-?- -b1=-qwerty-t-\-"---z-*-?- -b2=-qwerty-\t-\-"-\--\z-\*-\?- -b2=-qwerty-\t-\-"-\--\z-\*-\?- -b3=-$a-\t-\\-\"-\--\z-\*-\?- -b3=-$a-\t-\\-\"-\--\z-\*-\?- -c=-$a-\t-\\-\"-\--\z-\*-\?- -c=-$a-\t-\\-\"-\--\z-\*-\?- -c=-$a-\t-\\-\"-\--\z-\*-\?- -c=-$a-\t-\\-\"-\--\z-\*-\?- +b1=-qwerty-t-\-"-`---z-*-?- +b1=-qwerty-t-\-"-`---z-*-?- +b2=-qwerty-\t-\-"-`-\--\z-\*-\?- +b2=-qwerty-\t-\-"-`-\--\z-\*-\?- +b3=-$a-\t-\\-\"-\`-\--\z-\*-\?- +b3=-$a-\t-\\-\"-\`-\--\z-\*-\?- +c=-$a-\t-\\-\"-\`-\--\z-\*-\?- +c=-$a-\t-\\-\"-\`-\--\z-\*-\?- +c=-$a-\t-\\-\"-\`-\--\z-\*-\?- +c=-$a-\t-\\-\"-\`-\--\z-\*-\?- Done: 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 @@ # Test for correct handling of backslashes a=qwerty -b=-$a-\t-\\-\"-\--\z-\*-\?- +b=-$a-\t-\\-\"-\`-\--\z-\*-\?- echo b1=$b echo "b1=$b" -b="-$a-\t-\\-\"-\--\z-\*-\?-" +b="-$a-\t-\\-\"-\`-\--\z-\*-\?-" echo b2=$b echo "b2=$b" -b='-$a-\t-\\-\"-\--\z-\*-\?-' +b='-$a-\t-\\-\"-\`-\--\z-\*-\?-' echo b3=$b echo "b3=$b" |