aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-02-21 17:21:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-02-21 17:21:34 +0100
commite4a0612efdedca0182d444942c34317e9df28a27 (patch)
tree97bffa46406ae80dd4349c1ace455e1c6b7837e8
parent45dd87aac05ddf8bbfb110fde85ef875f3adfb65 (diff)
downloadbusybox-w32-e4a0612efdedca0182d444942c34317e9df28a27.tar.gz
busybox-w32-e4a0612efdedca0182d444942c34317e9df28a27.tar.bz2
busybox-w32-e4a0612efdedca0182d444942c34317e9df28a27.zip
hush: fix negative_arith.tests: glob-protect dash in "$((arith))"
function old new delta expand_vars_to_list 1026 1082 +56 parse_dollar 810 811 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 57/0) Total: 57 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 357a354e2..0a92f5da7 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3007,7 +3007,10 @@ static void x_mode_flush(void)
3007static void o_addqchr(o_string *o, int ch) 3007static void o_addqchr(o_string *o, int ch)
3008{ 3008{
3009 int sz = 1; 3009 int sz = 1;
3010 char *found = strchr("*?[\\" MAYBE_BRACES, ch); 3010 /* '-' is included because of this case:
3011 * >filename0 >filename1 >filename9; v='-'; echo filename[0"$v"9]
3012 */
3013 char *found = strchr("*?[-\\" MAYBE_BRACES, ch);
3011 if (found) 3014 if (found)
3012 sz++; 3015 sz++;
3013 o_grow_by(o, sz); 3016 o_grow_by(o, sz);
@@ -3024,7 +3027,7 @@ static void o_addQchr(o_string *o, int ch)
3024{ 3027{
3025 int sz = 1; 3028 int sz = 1;
3026 if ((o->o_expflags & EXP_FLAG_ESC_GLOB_CHARS) 3029 if ((o->o_expflags & EXP_FLAG_ESC_GLOB_CHARS)
3027 && strchr("*?[\\" MAYBE_BRACES, ch) 3030 && strchr("*?[-\\" MAYBE_BRACES, ch)
3028 ) { 3031 ) {
3029 sz++; 3032 sz++;
3030 o->data[o->length] = '\\'; 3033 o->data[o->length] = '\\';
@@ -3041,7 +3044,7 @@ static void o_addqblock(o_string *o, const char *str, int len)
3041 while (len) { 3044 while (len) {
3042 char ch; 3045 char ch;
3043 int sz; 3046 int sz;
3044 int ordinary_cnt = strcspn(str, "*?[\\" MAYBE_BRACES); 3047 int ordinary_cnt = strcspn(str, "*?[-\\" MAYBE_BRACES);
3045 if (ordinary_cnt > len) /* paranoia */ 3048 if (ordinary_cnt > len) /* paranoia */
3046 ordinary_cnt = len; 3049 ordinary_cnt = len;
3047 o_addblock(o, str, ordinary_cnt); 3050 o_addblock(o, str, ordinary_cnt);
@@ -3052,7 +3055,7 @@ static void o_addqblock(o_string *o, const char *str, int len)
3052 3055
3053 ch = *str++; 3056 ch = *str++;
3054 sz = 1; 3057 sz = 1;
3055 if (ch) { /* it is necessarily one of "*?[\\" MAYBE_BRACES */ 3058 if (ch) { /* it is necessarily one of "*?[-\\" MAYBE_BRACES */
3056 sz++; 3059 sz++;
3057 o->data[o->length] = '\\'; 3060 o->data[o->length] = '\\';
3058 o->length++; 3061 o->length++;
@@ -5049,7 +5052,7 @@ static int parse_dollar(o_string *as_string,
5049 ch = i_getch(input); 5052 ch = i_getch(input);
5050 nommu_addchr(as_string, ch); 5053 nommu_addchr(as_string, ch);
5051 o_addchr(dest, SPECIAL_VAR_SYMBOL); 5054 o_addchr(dest, SPECIAL_VAR_SYMBOL);
5052 o_addchr(dest, /*quote_mask |*/ '+'); 5055 o_addchr(dest, quote_mask | '+');
5053 if (!BB_MMU) 5056 if (!BB_MMU)
5054 pos = dest->length; 5057 pos = dest->length;
5055 if (!add_till_closing_bracket(dest, input, ')' | DOUBLE_CLOSE_CHAR_FLAG)) 5058 if (!add_till_closing_bracket(dest, input, ')' | DOUBLE_CLOSE_CHAR_FLAG))
@@ -6851,6 +6854,17 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
6851 res = expand_and_evaluate_arith(arg, NULL); 6854 res = expand_and_evaluate_arith(arg, NULL);
6852 debug_printf_subst("ARITH RES '"ARITH_FMT"'\n", res); 6855 debug_printf_subst("ARITH RES '"ARITH_FMT"'\n", res);
6853 sprintf(arith_buf, ARITH_FMT, res); 6856 sprintf(arith_buf, ARITH_FMT, res);
6857 if (res < 0
6858 && first_ch == (char)('+'|0x80)
6859 /* && (output->o_expflags & EXP_FLAG_ESC_GLOB_CHARS) */
6860 ) {
6861 /* Quoted negative ariths, like filename[0"$((-9))"],
6862 * should not be interpreted as glob ranges.
6863 * Convert leading '-' to '\-':
6864 */
6865 o_grow_by(output, 1);
6866 output->data[output->length++] = '\\';
6867 }
6854 o_addstr(output, arith_buf); 6868 o_addstr(output, arith_buf);
6855 break; 6869 break;
6856 } 6870 }