diff options
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 30 |
1 files changed, 17 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; |