summaryrefslogtreecommitdiffstats
path: root/debian/patches/bash52-012.diff
blob: 2a2976ede5a91f9ae0264cb5ec8f4b36547ec57f (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
			     BASH PATCH REPORT
			     =================

Bash-Release:	5.2
Patch-ID:	bash52-012

Bug-Reported-by:	Kerin Millar <kfm@plushkava.net>
Bug-Reference-ID:	<20221002095107.89561bc811e549b55644df11@plushkava.net>
Bug-Reference-URL:	https://lists.gnu.org/archive/html/bug-bash/2022-10/msg00001.html

Bug-Description:

When running in bash compatibility mode, nested command substitutions can
leave the `extglob' option enabled.

--- a/builtins/common.h
+++ b/builtins/common.h
@@ -257,6 +257,10 @@ extern int print_shift_error;
 extern int expand_once_flag;
 #endif
 
+#if defined (EXTENDED_GLOB)
+extern int extglob_flag;
+#endif
+
 extern int expaliases_flag;
 
 /* variables from source.def */
--- a/builtins/shopt.def
+++ b/builtins/shopt.def
@@ -149,6 +149,11 @@ static int shopt_set_complete_direxpand
 static int set_assoc_expand PARAMS((char *, int));
 #endif
 
+#if defined (EXTENDED_GLOB)
+int extglob_flag = EXTGLOB_DEFAULT;
+static int shopt_set_extglob PARAMS((char *, int));
+#endif
+
 int expaliases_flag = 0;
 static int shopt_set_expaliases PARAMS((char *, int));
 
@@ -206,7 +211,7 @@ static struct {
   { "extdebug", &debugging_mode, shopt_set_debug_mode },
 #endif
 #if defined (EXTENDED_GLOB)
-  { "extglob", &extended_glob, (shopt_set_func_t *)NULL },
+  { "extglob", &extglob_flag, shopt_set_extglob },
 #endif
   { "extquote", &extended_quote, (shopt_set_func_t *)NULL },
   { "failglob", &fail_glob_expansion, (shopt_set_func_t *)NULL },
@@ -377,7 +382,7 @@ reset_shopt_options ()
 #endif
 
 #if defined (EXTENDED_GLOB)
-  extended_glob = EXTGLOB_DEFAULT;
+  extended_glob = extglob_flag = EXTGLOB_DEFAULT;
 #endif
 
 #if defined (ARRAY_VARS)
@@ -643,6 +648,17 @@ shopt_set_expaliases (option_name, mode)
   return 0;
 }
 
+#if defined (EXTENDED_GLOB)
+static int
+shopt_set_extglob (option_name, mode)
+     char *option_name;
+     int mode;
+{
+  extended_glob = extglob_flag;
+  return 0;
+}
+#endif
+
 #if defined (READLINE)
 static int
 shopt_enable_hostname_completion (option_name, mode)
--- a/execute_cmd.c
+++ b/execute_cmd.c
@@ -3990,13 +3990,11 @@ execute_cond_node (cond)
       else
 #endif /* COND_REGEXP */
 	{
-	  int oe;
-	  oe = extended_glob;
 	  extended_glob = 1;
 	  result = binary_test (cond->op->word, arg1, arg2, TEST_PATMATCH|TEST_ARITHEXP|TEST_LOCALE)
 				  ? EXECUTION_SUCCESS
 				  : EXECUTION_FAILURE;
-	  extended_glob = oe;
+	  extended_glob = extglob_flag;
 	}
       if (arg1 != nullstr)
 	free (arg1);
--- a/parse.y
+++ b/parse.y
@@ -125,7 +125,7 @@ do { \
 } while (0)
 
 #if defined (EXTENDED_GLOB)
-extern int extended_glob;
+extern int extended_glob, extglob_flag;
 #endif
 
 #if defined (TRANSLATABLE_STRINGS)
@@ -3304,7 +3304,7 @@ reset_parser ()
 #if defined (EXTENDED_GLOB)
   /* Reset to global value of extended glob */
   if (parser_state & (PST_EXTPAT|PST_CMDSUBST))
-    extended_glob = global_extglob;
+    extended_glob = extglob_flag;
 #endif
   if (parser_state & (PST_CMDSUBST|PST_STRING))
     expand_aliases = expaliases_flag;
@@ -4124,10 +4124,10 @@ parse_comsub (qc, open, close, lenp, fla
     expand_aliases = posixly_correct != 0;
 #if defined (EXTENDED_GLOB)
   /* If (parser_state & PST_EXTPAT), we're parsing an extended pattern for a
-     conditional command and have already set global_extglob appropriately. */
+     conditional command and have already set extended_glob appropriately. */
   if (shell_compatibility_level <= 51 && was_extpat == 0)
     {
-      local_extglob = global_extglob = extended_glob;
+      local_extglob = extended_glob;
       extended_glob = 1;
     }
 #endif
@@ -4235,7 +4235,7 @@ xparse_dolparen (base, string, indp, fla
 {
   sh_parser_state_t ps;
   sh_input_line_state_t ls;
-  int orig_ind, nc, sflags, start_lineno;
+  int orig_ind, nc, sflags, start_lineno, local_extglob;
   char *ret, *ep, *ostring;
 
 /*debug_parser(1);*/
@@ -4278,7 +4278,7 @@ xparse_dolparen (base, string, indp, fla
      old value will be restored by restore_parser_state(). */
   expand_aliases = 0;
 #if defined (EXTENDED_GLOB)
-  global_extglob = extended_glob;		/* for reset_parser() */
+  local_extglob = extended_glob;
 #endif
 
   token_to_read = DOLPAREN;			/* let's trick the parser */
@@ -4296,6 +4296,9 @@ xparse_dolparen (base, string, indp, fla
   restore_input_line_state (&ls);
   restore_parser_state (&ps);
 
+#if defined (EXTENDED_GLOB)
+  extended_glob = local_extglob;
+#endif
   token_to_read = 0;
 
   /* If parse_string returns < 0, we need to jump to top level with the
@@ -4731,12 +4734,16 @@ cond_term ()
 	}
 
       /* rhs */
+#if defined (EXTENDED_GLOB)
       local_extglob = extended_glob;
       if (parser_state & PST_EXTPAT)
 	extended_glob = 1;
+#endif
       tok = read_token (READ);
+#if defined (EXTENDED_GLOB)
       if (parser_state & PST_EXTPAT)
 	extended_glob = local_extglob;
+#endif
       parser_state &= ~(PST_REGEXP|PST_EXTPAT);
 
       if (tok == WORD)
@@ -4783,7 +4790,6 @@ parse_cond_command ()
 {
   COND_COM *cexp;
 
-  global_extglob = extended_glob;
   cexp = cond_expr ();
   return (make_cond_command (cexp));
 }
--- a/patchlevel.h
+++ b/patchlevel.h
@@ -25,6 +25,6 @@
    regexp `^#define[ 	]*PATCHLEVEL', since that's what support/mkversion.sh
    looks for to find the patch level (for the sccs version string). */
 
-#define PATCHLEVEL 11
+#define PATCHLEVEL 12
 
 #endif /* _PATCHLEVEL_H_ */
--- a/y.tab.c
+++ b/y.tab.c
@@ -175,7 +175,7 @@ do { \
 } while (0)
 
 #if defined (EXTENDED_GLOB)
-extern int extended_glob;
+extern int extended_glob, extglob_flag;
 #endif
 
 #if defined (TRANSLATABLE_STRINGS)
@@ -5615,7 +5615,7 @@ reset_parser ()
 #if defined (EXTENDED_GLOB)
   /* Reset to global value of extended glob */
   if (parser_state & (PST_EXTPAT|PST_CMDSUBST))
-    extended_glob = global_extglob;
+    extended_glob = extglob_flag;
 #endif
   if (parser_state & (PST_CMDSUBST|PST_STRING))
     expand_aliases = expaliases_flag;
@@ -6435,10 +6435,10 @@ parse_comsub (qc, open, close, lenp, fla
     expand_aliases = posixly_correct != 0;
 #if defined (EXTENDED_GLOB)
   /* If (parser_state & PST_EXTPAT), we're parsing an extended pattern for a
-     conditional command and have already set global_extglob appropriately. */
+     conditional command and have already set extended_glob appropriately. */
   if (shell_compatibility_level <= 51 && was_extpat == 0)
     {
-      local_extglob = global_extglob = extended_glob;
+      local_extglob = extended_glob;
       extended_glob = 1;
     }
 #endif
@@ -6546,7 +6546,7 @@ xparse_dolparen (base, string, indp, fla
 {
   sh_parser_state_t ps;
   sh_input_line_state_t ls;
-  int orig_ind, nc, sflags, start_lineno;
+  int orig_ind, nc, sflags, start_lineno, local_extglob;
   char *ret, *ep, *ostring;
 
 /*debug_parser(1);*/
@@ -6589,7 +6589,7 @@ xparse_dolparen (base, string, indp, fla
      old value will be restored by restore_parser_state(). */
   expand_aliases = 0;
 #if defined (EXTENDED_GLOB)
-  global_extglob = extended_glob;		/* for reset_parser() */
+  local_extglob = extended_glob;
 #endif
 
   token_to_read = DOLPAREN;			/* let's trick the parser */
@@ -6607,6 +6607,9 @@ xparse_dolparen (base, string, indp, fla
   restore_input_line_state (&ls);
   restore_parser_state (&ps);
 
+#if defined (EXTENDED_GLOB)
+  extended_glob = local_extglob;
+#endif
   token_to_read = 0;
 
   /* If parse_string returns < 0, we need to jump to top level with the
@@ -7042,12 +7045,16 @@ cond_term ()
 	}
 
       /* rhs */
+#if defined (EXTENDED_GLOB)
       local_extglob = extended_glob;
       if (parser_state & PST_EXTPAT)
 	extended_glob = 1;
+#endif
       tok = read_token (READ);
+#if defined (EXTENDED_GLOB)
       if (parser_state & PST_EXTPAT)
 	extended_glob = local_extglob;
+#endif
       parser_state &= ~(PST_REGEXP|PST_EXTPAT);
 
       if (tok == WORD)
@@ -7094,7 +7101,6 @@ parse_cond_command ()
 {
   COND_COM *cexp;
 
-  global_extglob = extended_glob;
   cexp = cond_expr ();
   return (make_cond_command (cexp));
 }