diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-03-02 18:12:12 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-03-02 18:12:12 +0100 |
commit | 55f8133a4fb207d6fecd02f43c36809d3c2f6672 (patch) | |
tree | 5f57cd305d494a914980022bb6767b2e8faaf676 | |
parent | 744a20d8f9b1baf7c8cc1ed33ec744a52c89768f (diff) | |
download | busybox-w32-55f8133a4fb207d6fecd02f43c36809d3c2f6672.tar.gz busybox-w32-55f8133a4fb207d6fecd02f43c36809d3c2f6672.tar.bz2 busybox-w32-55f8133a4fb207d6fecd02f43c36809d3c2f6672.zip |
shell: tweak bkslash_in_varexp.tests, add bkslash_in_varexp1.tests
It turns out bkslash_in_varexp.tests was a bash bug :]
ash and hush fail "corrected" bkslash_in_varexp.tests as well,
just not as badly as I thought (hush gets half of the cases right).
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rwxr-xr-x | shell/ash_test/ash-quoting/bkslash_in_varexp.tests | 12 | ||||
-rw-r--r-- | shell/ash_test/ash-quoting/bkslash_in_varexp1.right | 5 | ||||
-rwxr-xr-x | shell/ash_test/ash-quoting/bkslash_in_varexp1.tests | 6 | ||||
-rw-r--r-- | shell/hush.c | 7 | ||||
-rwxr-xr-x | shell/hush_test/hush-quoting/bkslash_in_varexp.tests | 12 | ||||
-rw-r--r-- | shell/hush_test/hush-quoting/bkslash_in_varexp1.right | 5 | ||||
-rwxr-xr-x | shell/hush_test/hush-quoting/bkslash_in_varexp1.tests | 6 | ||||
-rw-r--r-- | shell/match.c | 2 |
8 files changed, 50 insertions, 5 deletions
diff --git a/shell/ash_test/ash-quoting/bkslash_in_varexp.tests b/shell/ash_test/ash-quoting/bkslash_in_varexp.tests index 41b31ab54..6c7b4b0cc 100755 --- a/shell/ash_test/ash-quoting/bkslash_in_varexp.tests +++ b/shell/ash_test/ash-quoting/bkslash_in_varexp.tests | |||
@@ -1,4 +1,14 @@ | |||
1 | x=a | 1 | x='a]' |
2 | # | ||
3 | # \] is not a valid escape for ] in set glob expression. | ||
4 | # Glob sets have no escaping at all: | ||
5 | # ] can be in a set if it is the first char: []abc], | ||
6 | # dash can be in a set if it is first or last: [abc-], | ||
7 | # [ and \ need no protections at all: [a[b\c] is a valid set of 5 chars. | ||
8 | # | ||
9 | # bash-4.3.43 misinterprets [a\]] as "set of 'a' or ']'". | ||
10 | # Correct interpretation is "set of 'a' or '\', followed by ']'". | ||
11 | # | ||
2 | echo Nothing:${x#[a\]]} | 12 | echo Nothing:${x#[a\]]} |
3 | echo Nothing:"${x#[a\]]}" | 13 | echo Nothing:"${x#[a\]]}" |
4 | echo Nothing:${x%[a\]]} | 14 | echo Nothing:${x%[a\]]} |
diff --git a/shell/ash_test/ash-quoting/bkslash_in_varexp1.right b/shell/ash_test/ash-quoting/bkslash_in_varexp1.right new file mode 100644 index 000000000..d03047024 --- /dev/null +++ b/shell/ash_test/ash-quoting/bkslash_in_varexp1.right | |||
@@ -0,0 +1,5 @@ | |||
1 | Nothing: | ||
2 | Nothing: | ||
3 | Nothing: | ||
4 | Nothing: | ||
5 | Ok:0 | ||
diff --git a/shell/ash_test/ash-quoting/bkslash_in_varexp1.tests b/shell/ash_test/ash-quoting/bkslash_in_varexp1.tests new file mode 100755 index 000000000..3c817eae1 --- /dev/null +++ b/shell/ash_test/ash-quoting/bkslash_in_varexp1.tests | |||
@@ -0,0 +1,6 @@ | |||
1 | x=a | ||
2 | echo Nothing:${x#[]a]} | ||
3 | echo Nothing:"${x#[]a]}" | ||
4 | echo Nothing:${x%[]a]} | ||
5 | echo Nothing:"${x%[]a]}" | ||
6 | echo Ok:$? | ||
diff --git a/shell/hush.c b/shell/hush.c index e005b0a20..da4967a8a 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -4488,7 +4488,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign | |||
4488 | } | 4488 | } |
4489 | if (ch == end_ch | 4489 | if (ch == end_ch |
4490 | # if BASH_SUBSTR || BASH_PATTERN_SUBST | 4490 | # if BASH_SUBSTR || BASH_PATTERN_SUBST |
4491 | || ch == end_char2 | 4491 | || ch == end_char2 |
4492 | # endif | 4492 | # endif |
4493 | ) { | 4493 | ) { |
4494 | if (!dbl) | 4494 | if (!dbl) |
@@ -5842,17 +5842,18 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha | |||
5842 | unsigned scan_flags = pick_scan(exp_op, *exp_word); | 5842 | unsigned scan_flags = pick_scan(exp_op, *exp_word); |
5843 | if (exp_op == *exp_word) /* ## or %% */ | 5843 | if (exp_op == *exp_word) /* ## or %% */ |
5844 | exp_word++; | 5844 | exp_word++; |
5845 | debug_printf_expand("expand: exp_word:'%s'\n", exp_word); | ||
5845 | exp_exp_word = encode_then_expand_string(exp_word, /*process_bkslash:*/ 1, /*unbackslash:*/ 1); | 5846 | exp_exp_word = encode_then_expand_string(exp_word, /*process_bkslash:*/ 1, /*unbackslash:*/ 1); |
5846 | if (exp_exp_word) | 5847 | if (exp_exp_word) |
5847 | exp_word = exp_exp_word; | 5848 | exp_word = exp_exp_word; |
5849 | debug_printf_expand("expand: exp_exp_word:'%s'\n", exp_word); | ||
5848 | /* HACK ALERT. We depend here on the fact that | 5850 | /* HACK ALERT. We depend here on the fact that |
5849 | * G.global_argv and results of utoa and get_local_var_value | 5851 | * G.global_argv and results of utoa and get_local_var_value |
5850 | * are actually in writable memory: | 5852 | * are actually in writable memory: |
5851 | * scan_and_match momentarily stores NULs there. */ | 5853 | * scan_and_match momentarily stores NULs there. */ |
5852 | t = (char*)val; | 5854 | t = (char*)val; |
5853 | loc = scan_and_match(t, exp_word, scan_flags); | 5855 | loc = scan_and_match(t, exp_word, scan_flags); |
5854 | //bb_error_msg("op:%c str:'%s' pat:'%s' res:'%s'", | 5856 | debug_printf_expand("op:%c str:'%s' pat:'%s' res:'%s'\n", exp_op, t, exp_word, loc); |
5855 | // exp_op, t, exp_word, loc); | ||
5856 | free(exp_exp_word); | 5857 | free(exp_exp_word); |
5857 | if (loc) { /* match was found */ | 5858 | if (loc) { /* match was found */ |
5858 | if (scan_flags & SCAN_MATCH_LEFT_HALF) /* #[#] */ | 5859 | if (scan_flags & SCAN_MATCH_LEFT_HALF) /* #[#] */ |
diff --git a/shell/hush_test/hush-quoting/bkslash_in_varexp.tests b/shell/hush_test/hush-quoting/bkslash_in_varexp.tests index 41b31ab54..6c7b4b0cc 100755 --- a/shell/hush_test/hush-quoting/bkslash_in_varexp.tests +++ b/shell/hush_test/hush-quoting/bkslash_in_varexp.tests | |||
@@ -1,4 +1,14 @@ | |||
1 | x=a | 1 | x='a]' |
2 | # | ||
3 | # \] is not a valid escape for ] in set glob expression. | ||
4 | # Glob sets have no escaping at all: | ||
5 | # ] can be in a set if it is the first char: []abc], | ||
6 | # dash can be in a set if it is first or last: [abc-], | ||
7 | # [ and \ need no protections at all: [a[b\c] is a valid set of 5 chars. | ||
8 | # | ||
9 | # bash-4.3.43 misinterprets [a\]] as "set of 'a' or ']'". | ||
10 | # Correct interpretation is "set of 'a' or '\', followed by ']'". | ||
11 | # | ||
2 | echo Nothing:${x#[a\]]} | 12 | echo Nothing:${x#[a\]]} |
3 | echo Nothing:"${x#[a\]]}" | 13 | echo Nothing:"${x#[a\]]}" |
4 | echo Nothing:${x%[a\]]} | 14 | echo Nothing:${x%[a\]]} |
diff --git a/shell/hush_test/hush-quoting/bkslash_in_varexp1.right b/shell/hush_test/hush-quoting/bkslash_in_varexp1.right new file mode 100644 index 000000000..d03047024 --- /dev/null +++ b/shell/hush_test/hush-quoting/bkslash_in_varexp1.right | |||
@@ -0,0 +1,5 @@ | |||
1 | Nothing: | ||
2 | Nothing: | ||
3 | Nothing: | ||
4 | Nothing: | ||
5 | Ok:0 | ||
diff --git a/shell/hush_test/hush-quoting/bkslash_in_varexp1.tests b/shell/hush_test/hush-quoting/bkslash_in_varexp1.tests new file mode 100755 index 000000000..3c817eae1 --- /dev/null +++ b/shell/hush_test/hush-quoting/bkslash_in_varexp1.tests | |||
@@ -0,0 +1,6 @@ | |||
1 | x=a | ||
2 | echo Nothing:${x#[]a]} | ||
3 | echo Nothing:"${x#[]a]}" | ||
4 | echo Nothing:${x%[]a]} | ||
5 | echo Nothing:"${x%[]a]}" | ||
6 | echo Ok:$? | ||
diff --git a/shell/match.c b/shell/match.c index fee3cf2a8..8f2a2fb38 100644 --- a/shell/match.c +++ b/shell/match.c | |||
@@ -71,9 +71,11 @@ char* FAST_FUNC scan_and_match(char *string, const char *pattern, unsigned flags | |||
71 | if (flags & SCAN_MATCH_LEFT_HALF) { | 71 | if (flags & SCAN_MATCH_LEFT_HALF) { |
72 | *loc = '\0'; | 72 | *loc = '\0'; |
73 | r = fnmatch(pattern, string, 0); | 73 | r = fnmatch(pattern, string, 0); |
74 | //bb_error_msg("fnmatch('%s','%s',0):%d", pattern, string, r); | ||
74 | *loc = c; | 75 | *loc = c; |
75 | } else { | 76 | } else { |
76 | r = fnmatch(pattern, loc, 0); | 77 | r = fnmatch(pattern, loc, 0); |
78 | //bb_error_msg("fnmatch('%s','%s',0):%d", pattern, string, r); | ||
77 | } | 79 | } |
78 | if (r == 0) /* match found */ | 80 | if (r == 0) /* match found */ |
79 | return loc; | 81 | return loc; |