summaryrefslogtreecommitdiff
path: root/package/busybox/busybox-1.17.2/busybox-1.17.2-hush.patch
blob: 3bcb5f31f7ca3ad842d60e5c01f2ca3687d7eab1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
diff -urpN busybox-1.17.2/shell/hush.c busybox-1.17.2-hush/shell/hush.c
--- busybox-1.17.2/shell/hush.c	2010-08-23 02:45:15.000000000 +0200
+++ busybox-1.17.2-hush/shell/hush.c	2010-09-04 19:44:57.381391123 +0200
@@ -1853,7 +1853,7 @@ static void o_addblock_duplicate_backsla
 	while (len) {
 		o_addchr(o, *str);
 		if (*str++ == '\\'
-		 && (*str != '*' && *str != '?' && *str != '[')
+//		 && (*str != '*' && *str != '?' && *str != '[')
 		) {
 			o_addchr(o, '\\');
 		}
@@ -2834,18 +2834,22 @@ static NOINLINE int expand_vars_to_list(
 	return n;
 }
 
-static char **expand_variables(char **argv, int or_mask)
+enum {
+	EXPVAR_FLAG_GLOB = 0x200,
+	EXPVAR_FLAG_ESCAPE_VARS = 0x100,
+	EXPVAR_FLAG_SINGLEWORD = 0x80, /* must be 0x80 */
+};
+static char **expand_variables(char **argv, unsigned or_mask)
 {
 	int n;
 	char **list;
 	char **v;
 	o_string output = NULL_O_STRING;
 
-	if (or_mask & 0x100) {
-		output.o_escape = 1; /* protect against globbing for "$var" */
-		/* (unquoted $var will temporarily switch it off) */
-		output.o_glob = 1;
-	}
+	/* protect against globbing for "$var"? */
+	/* (unquoted $var will temporarily switch it off) */
+	output.o_escape = 1 & (or_mask / EXPVAR_FLAG_ESCAPE_VARS);
+	output.o_glob = 1 & (or_mask / EXPVAR_FLAG_GLOB);
 
 	n = 0;
 	v = argv;
@@ -2863,13 +2867,13 @@ static char **expand_variables(char **ar
 
 static char **expand_strvec_to_strvec(char **argv)
 {
-	return expand_variables(argv, 0x100);
+	return expand_variables(argv, EXPVAR_FLAG_GLOB | EXPVAR_FLAG_ESCAPE_VARS);
 }
 
 #if ENABLE_HUSH_BASH_COMPAT
 static char **expand_strvec_to_strvec_singleword_noglob(char **argv)
 {
-	return expand_variables(argv, 0x80);
+	return expand_variables(argv, EXPVAR_FLAG_SINGLEWORD);
 }
 #endif
 
@@ -2909,15 +2913,15 @@ static char **expand_strvec_to_strvec_si
 #endif
 
 /* Used for expansion of right hand of assignments */
-/* NB: should NOT do globbing! "export v=/bin/c*; env | grep ^v=" outputs
- * "v=/bin/c*" */
+/* NB: should NOT do globbing!
+ * "export v=/bin/c*; env | grep ^v=" outputs "v=/bin/c*" */
 static char *expand_string_to_string(const char *str)
 {
 	char *argv[2], **list;
 
 	argv[0] = (char*)str;
 	argv[1] = NULL;
-	list = expand_variables(argv, 0x80); /* 0x80: singleword expansion */
+	list = expand_variables(argv, EXPVAR_FLAG_ESCAPE_VARS | EXPVAR_FLAG_SINGLEWORD);
 	if (HUSH_DEBUG)
 		if (!list[0] || list[1])
 			bb_error_msg_and_die("BUG in varexp2");
@@ -2933,7 +2937,7 @@ static char* expand_strvec_to_string(cha
 {
 	char **list;
 
-	list = expand_variables(argv, 0x80);
+	list = expand_variables(argv, EXPVAR_FLAG_SINGLEWORD);
 	/* Convert all NULs to spaces */
 	if (list[0]) {
 		int n = 1;
diff -urpN busybox-1.17.2/shell/hush_test/hush-vars/var_unbackslash.right busybox-1.17.2-hush/shell/hush_test/hush-vars/var_unbackslash.right
--- busybox-1.17.2/shell/hush_test/hush-vars/var_unbackslash.right	1970-01-01 01:00:00.000000000 +0100
+++ busybox-1.17.2-hush/shell/hush_test/hush-vars/var_unbackslash.right	2010-09-04 19:44:57.382391186 +0200
@@ -0,0 +1,9 @@
+b1=-qwerty-t-\-"---z-*-?-
+b1=-qwerty-t-\-"---z-*-?-
+b2=-$a-\t-\\-\"-\--\z-\*-\?-
+b2=-$a-\t-\\-\"-\--\z-\*-\?-
+c=-$a-\t-\\-\"-\--\z-\*-\?-
+c=-$a-\t-\\-\"-\--\z-\*-\?-
+c=-$a-\t-\\-\"-\--\z-\*-\?-
+c=-$a-\t-\\-\"-\--\z-\*-\?-
+Done: 0
diff -urpN busybox-1.17.2/shell/hush_test/hush-vars/var_unbackslash.tests busybox-1.17.2-hush/shell/hush_test/hush-vars/var_unbackslash.tests
--- busybox-1.17.2/shell/hush_test/hush-vars/var_unbackslash.tests	1970-01-01 01:00:00.000000000 +0100
+++ busybox-1.17.2-hush/shell/hush_test/hush-vars/var_unbackslash.tests	2010-09-04 19:44:57.382391186 +0200
@@ -0,0 +1,20 @@
+# Test for correct handling of backslashes
+a=qwerty
+
+b=-$a-\t-\\-\"-\--\z-\*-\?-
+echo b1=$b
+echo "b1=$b"
+b='-$a-\t-\\-\"-\--\z-\*-\?-'
+echo b2=$b
+echo "b2=$b"
+
+c=$b
+echo "c=$c"
+c=${b}
+echo "c=$c"
+c="$b"
+echo "c=$c"
+c="${b}"
+echo "c=$c"
+
+echo "Done: $?"