diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-09 21:59:49 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-09 21:59:49 +0200 |
| commit | 468c326d6a9035314add6d431301f3840629c976 (patch) | |
| tree | fb2fbca7fcbeec23681c8e97a311f7eae612281c /shell | |
| parent | 5e891f30d376bb83d391790173b1c189f4bb22cd (diff) | |
| download | busybox-w32-1_17_3.tar.gz busybox-w32-1_17_3.tar.bz2 busybox-w32-1_17_3.zip | |
Apply post-1.17.2 fixes, bump version to 1.17.31_17_3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/hush.c | 30 | ||||
| -rw-r--r-- | shell/hush_test/hush-vars/var_unbackslash.right | 9 | ||||
| -rwxr-xr-x | shell/hush_test/hush-vars/var_unbackslash.tests | 20 |
3 files changed, 46 insertions, 13 deletions
diff --git a/shell/hush.c b/shell/hush.c index 01bc96ce6..3665e40f2 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -1853,7 +1853,7 @@ static void o_addblock_duplicate_backslash(o_string *o, const char *str, int len | |||
| 1853 | while (len) { | 1853 | while (len) { |
| 1854 | o_addchr(o, *str); | 1854 | o_addchr(o, *str); |
| 1855 | if (*str++ == '\\' | 1855 | if (*str++ == '\\' |
| 1856 | && (*str != '*' && *str != '?' && *str != '[') | 1856 | // && (*str != '*' && *str != '?' && *str != '[') |
| 1857 | ) { | 1857 | ) { |
| 1858 | o_addchr(o, '\\'); | 1858 | o_addchr(o, '\\'); |
| 1859 | } | 1859 | } |
| @@ -2834,18 +2834,22 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char | |||
| 2834 | return n; | 2834 | return n; |
| 2835 | } | 2835 | } |
| 2836 | 2836 | ||
| 2837 | static char **expand_variables(char **argv, int or_mask) | 2837 | enum { |
| 2838 | EXPVAR_FLAG_GLOB = 0x200, | ||
| 2839 | EXPVAR_FLAG_ESCAPE_VARS = 0x100, | ||
| 2840 | EXPVAR_FLAG_SINGLEWORD = 0x80, /* must be 0x80 */ | ||
| 2841 | }; | ||
| 2842 | static char **expand_variables(char **argv, unsigned or_mask) | ||
| 2838 | { | 2843 | { |
| 2839 | int n; | 2844 | int n; |
| 2840 | char **list; | 2845 | char **list; |
| 2841 | char **v; | 2846 | char **v; |
| 2842 | o_string output = NULL_O_STRING; | 2847 | o_string output = NULL_O_STRING; |
| 2843 | 2848 | ||
| 2844 | if (or_mask & 0x100) { | 2849 | /* protect against globbing for "$var"? */ |
| 2845 | output.o_escape = 1; /* protect against globbing for "$var" */ | 2850 | /* (unquoted $var will temporarily switch it off) */ |
| 2846 | /* (unquoted $var will temporarily switch it off) */ | 2851 | output.o_escape = 1 & (or_mask / EXPVAR_FLAG_ESCAPE_VARS); |
| 2847 | output.o_glob = 1; | 2852 | output.o_glob = 1 & (or_mask / EXPVAR_FLAG_GLOB); |
| 2848 | } | ||
| 2849 | 2853 | ||
| 2850 | n = 0; | 2854 | n = 0; |
| 2851 | v = argv; | 2855 | v = argv; |
| @@ -2863,13 +2867,13 @@ static char **expand_variables(char **argv, int or_mask) | |||
| 2863 | 2867 | ||
| 2864 | static char **expand_strvec_to_strvec(char **argv) | 2868 | static char **expand_strvec_to_strvec(char **argv) |
| 2865 | { | 2869 | { |
| 2866 | return expand_variables(argv, 0x100); | 2870 | return expand_variables(argv, EXPVAR_FLAG_GLOB | EXPVAR_FLAG_ESCAPE_VARS); |
| 2867 | } | 2871 | } |
| 2868 | 2872 | ||
| 2869 | #if ENABLE_HUSH_BASH_COMPAT | 2873 | #if ENABLE_HUSH_BASH_COMPAT |
| 2870 | static char **expand_strvec_to_strvec_singleword_noglob(char **argv) | 2874 | static char **expand_strvec_to_strvec_singleword_noglob(char **argv) |
| 2871 | { | 2875 | { |
| 2872 | return expand_variables(argv, 0x80); | 2876 | return expand_variables(argv, EXPVAR_FLAG_SINGLEWORD); |
| 2873 | } | 2877 | } |
| 2874 | #endif | 2878 | #endif |
| 2875 | 2879 | ||
| @@ -2909,15 +2913,15 @@ static char **expand_strvec_to_strvec_singleword_noglob_cond(char **argv) | |||
| 2909 | #endif | 2913 | #endif |
| 2910 | 2914 | ||
| 2911 | /* Used for expansion of right hand of assignments */ | 2915 | /* Used for expansion of right hand of assignments */ |
| 2912 | /* NB: should NOT do globbing! "export v=/bin/c*; env | grep ^v=" outputs | 2916 | /* NB: should NOT do globbing! |
| 2913 | * "v=/bin/c*" */ | 2917 | * "export v=/bin/c*; env | grep ^v=" outputs "v=/bin/c*" */ |
| 2914 | static char *expand_string_to_string(const char *str) | 2918 | static char *expand_string_to_string(const char *str) |
| 2915 | { | 2919 | { |
| 2916 | char *argv[2], **list; | 2920 | char *argv[2], **list; |
| 2917 | 2921 | ||
| 2918 | argv[0] = (char*)str; | 2922 | argv[0] = (char*)str; |
| 2919 | argv[1] = NULL; | 2923 | argv[1] = NULL; |
| 2920 | list = expand_variables(argv, 0x80); /* 0x80: singleword expansion */ | 2924 | list = expand_variables(argv, EXPVAR_FLAG_ESCAPE_VARS | EXPVAR_FLAG_SINGLEWORD); |
| 2921 | if (HUSH_DEBUG) | 2925 | if (HUSH_DEBUG) |
| 2922 | if (!list[0] || list[1]) | 2926 | if (!list[0] || list[1]) |
| 2923 | bb_error_msg_and_die("BUG in varexp2"); | 2927 | bb_error_msg_and_die("BUG in varexp2"); |
| @@ -2933,7 +2937,7 @@ static char* expand_strvec_to_string(char **argv) | |||
| 2933 | { | 2937 | { |
| 2934 | char **list; | 2938 | char **list; |
| 2935 | 2939 | ||
| 2936 | list = expand_variables(argv, 0x80); | 2940 | list = expand_variables(argv, EXPVAR_FLAG_SINGLEWORD); |
| 2937 | /* Convert all NULs to spaces */ | 2941 | /* Convert all NULs to spaces */ |
| 2938 | if (list[0]) { | 2942 | if (list[0]) { |
| 2939 | int n = 1; | 2943 | int n = 1; |
diff --git a/shell/hush_test/hush-vars/var_unbackslash.right b/shell/hush_test/hush-vars/var_unbackslash.right new file mode 100644 index 000000000..c48079279 --- /dev/null +++ b/shell/hush_test/hush-vars/var_unbackslash.right | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | b1=-qwerty-t-\-"---z-*-?- | ||
| 2 | b1=-qwerty-t-\-"---z-*-?- | ||
| 3 | b2=-$a-\t-\\-\"-\--\z-\*-\?- | ||
| 4 | b2=-$a-\t-\\-\"-\--\z-\*-\?- | ||
| 5 | c=-$a-\t-\\-\"-\--\z-\*-\?- | ||
| 6 | c=-$a-\t-\\-\"-\--\z-\*-\?- | ||
| 7 | c=-$a-\t-\\-\"-\--\z-\*-\?- | ||
| 8 | c=-$a-\t-\\-\"-\--\z-\*-\?- | ||
| 9 | Done: 0 | ||
diff --git a/shell/hush_test/hush-vars/var_unbackslash.tests b/shell/hush_test/hush-vars/var_unbackslash.tests new file mode 100755 index 000000000..2377cd50b --- /dev/null +++ b/shell/hush_test/hush-vars/var_unbackslash.tests | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | # Test for correct handling of backslashes | ||
| 2 | a=qwerty | ||
| 3 | |||
| 4 | b=-$a-\t-\\-\"-\--\z-\*-\?- | ||
| 5 | echo b1=$b | ||
| 6 | echo "b1=$b" | ||
| 7 | b='-$a-\t-\\-\"-\--\z-\*-\?-' | ||
| 8 | echo b2=$b | ||
| 9 | echo "b2=$b" | ||
| 10 | |||
| 11 | c=$b | ||
| 12 | echo "c=$c" | ||
| 13 | c=${b} | ||
| 14 | echo "c=$c" | ||
| 15 | c="$b" | ||
| 16 | echo "c=$c" | ||
| 17 | c="${b}" | ||
| 18 | echo "c=$c" | ||
| 19 | |||
| 20 | echo "Done: $?" | ||
