source: patches/bash-4.0-branch_update-1.patch@ 82c4aa0

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 82c4aa0 was c822ddc, checked in by Jim Gifford <clfs@…>, 16 years ago

Added Bash 4.0 Branch Update Patch

  • Property mode set to 100644
File size: 9.9 KB
RevLine 
[c822ddc]1Submitted By: Jim Gifford (jim at cross-lfs dot org)
2Date: 01-08-2009
3Initial Package Version: 4.0
4Origin: Upstream
5Upstream Status: Applied
6Description: Fixes from the Mailing List - Bash Bug
7 http://lists.gnu.org/archive/html/bug-bash/2009-02/index.html
8
9diff -Naur bash-4.0.orig/arrayfunc.c bash-4.0/arrayfunc.c
10--- bash-4.0.orig/arrayfunc.c 2009-01-04 11:32:21.000000000 -0800
11+++ bash-4.0/arrayfunc.c 2009-02-27 08:59:33.307629837 -0800
12@@ -604,64 +604,7 @@
13 }
14 }
15
16-/* This function assumes s[i] == '['; returns with s[ret] == ']' if
17- an array subscript is correctly parsed. */
18-int
19-skipsubscript (s, i)
20- const char *s;
21- int i;
22-{
23- int count, c;
24-#if defined (HANDLE_MULTIBYTE)
25- mbstate_t state, state_bak;
26- size_t slength, mblength;
27-#endif
28-
29-#if defined (HANDLE_MULTIBYTE)
30- memset (&state, '\0', sizeof (mbstate_t));
31- slength = strlen (s + i);
32-#endif
33-
34- count = 1;
35- while (count)
36- {
37- /* Advance one (possibly multibyte) character in S starting at I. */
38-#if defined (HANDLE_MULTIBYTE)
39- if (MB_CUR_MAX > 1)
40- {
41- state_bak = state;
42- mblength = mbrlen (s + i, slength, &state);
43-
44- if (MB_INVALIDCH (mblength))
45- {
46- state = state_bak;
47- i++;
48- slength--;
49- }
50- else if (MB_NULLWCH (mblength))
51- return i;
52- else
53- {
54- i += mblength;
55- slength -= mblength;
56- }
57- }
58- else
59-#endif
60- ++i;
61-
62- c = s[i];
63-
64- if (c == 0)
65- break;
66- else if (c == '[')
67- count++;
68- else if (c == ']')
69- count--;
70- }
71-
72- return i;
73-}
74+/* skipsubscript moved to subst.c to use private functions. 2009/02/24. */
75
76 /* This function is called with SUB pointing to just after the beginning
77 `[' of an array subscript and removes the array element to which SUB
78diff -Naur bash-4.0.orig/builtins/declare.def bash-4.0/builtins/declare.def
79--- bash-4.0.orig/builtins/declare.def 2009-01-04 11:32:22.000000000 -0800
80+++ bash-4.0/builtins/declare.def 2009-02-27 08:59:13.626367370 -0800
81@@ -287,6 +287,12 @@
82 name[offset - 1] = '\0';
83 }
84 }
85+ else if (legal_identifier (name) == 0)
86+ {
87+ sh_invalidid (name);
88+ assign_error++;
89+ NEXT_VARIABLE ();
90+ }
91 else
92 value = "";
93
94@@ -295,6 +301,13 @@
95 subscript_start = (char *)NULL;
96 if (t = strchr (name, '[')) /* ] */
97 {
98+ /* If offset != 0 we have already validated any array reference */
99+ if (offset == 0 && valid_array_reference (name) == 0)
100+ {
101+ sh_invalidid (name);
102+ assign_error++;
103+ NEXT_VARIABLE ();
104+ }
105 subscript_start = t;
106 *t = '\0';
107 making_array_special = 1;
108@@ -484,7 +497,7 @@
109 }
110 /* declare -a name[[n]] or declare name[n] makes name an indexed
111 array variable. */
112- else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0)
113+ else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0 && assoc_p (var) == 0)
114 var = convert_var_to_array (var);
115 #endif /* ARRAY_VARS */
116
117diff -Naur bash-4.0.orig/builtins/exit.def bash-4.0/builtins/exit.def
118--- bash-4.0.orig/builtins/exit.def 2009-01-04 11:32:22.000000000 -0800
119+++ bash-4.0/builtins/exit.def 2009-02-27 08:57:04.682105881 -0800
120@@ -113,7 +113,7 @@
121 for (i = stopmsg = 0; i < js.j_jobslots; i++)
122 if (jobs[i] && STOPPED (i))
123 stopmsg = JSTOPPED;
124- else if (check_jobs_at_exit && stopmsg == 0 && RUNNING (i))
125+ else if (check_jobs_at_exit && stopmsg == 0 && jobs[i] && RUNNING (i))
126 stopmsg = JRUNNING;
127
128 if (stopmsg == JSTOPPED)
129diff -Naur bash-4.0.orig/parse.y bash-4.0/parse.y
130--- bash-4.0.orig/parse.y 2009-01-08 05:29:12.000000000 -0800
131+++ bash-4.0/parse.y 2009-02-27 08:59:51.884818830 -0800
132@@ -1615,10 +1615,11 @@
133 {
134 int *ret;
135
136- ret = (int *)xmalloc (3 * sizeof (int));
137+ ret = (int *)xmalloc (4 * sizeof (int));
138 ret[0] = last_read_token;
139 ret[1] = token_before_that;
140 ret[2] = two_tokens_ago;
141+ ret[3] = current_token;
142 return ret;
143 }
144
145@@ -1631,6 +1632,7 @@
146 last_read_token = ts[0];
147 token_before_that = ts[1];
148 two_tokens_ago = ts[2];
149+ current_token = ts[3];
150 }
151
152 /*
153@@ -2668,6 +2670,7 @@
154 FREE (word_desc_to_read);
155 word_desc_to_read = (WORD_DESC *)NULL;
156
157+ current_token = '\n'; /* XXX */
158 last_read_token = '\n';
159 token_to_read = '\n';
160 }
161@@ -2915,6 +2918,7 @@
162 #define P_DQUOTE 0x04
163 #define P_COMMAND 0x08 /* parsing a command, so look for comments */
164 #define P_BACKQUOTE 0x10 /* parsing a backquoted command substitution */
165+#define P_ARRAYSUB 0x20 /* parsing a [...] array subscript for assignment */
166
167 /* Lexical state while parsing a grouping construct or $(...). */
168 #define LEX_WASDOL 0x001
169@@ -3129,6 +3133,8 @@
170 APPEND_NESTRET ();
171 FREE (nestret);
172 }
173+ else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
174+ goto parse_dollar_word;
175 }
176 /* Parse an old-style command substitution within double quotes as a
177 single word. */
178@@ -3145,6 +3151,7 @@
179 else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
180 /* check for $(), $[], or ${} inside quoted string. */
181 {
182+parse_dollar_word:
183 if (open == ch) /* undo previous increment */
184 count--;
185 if (ch == '(') /* ) */
186@@ -3306,7 +3313,7 @@
187 }
188
189 /* Meta-characters that can introduce a reserved word. Not perfect yet. */
190- if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && shellmeta(ch))
191+ if MBTEST((tflags & LEX_PASSNEXT) == 0 && (tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && shellmeta(ch))
192 {
193 /* Add this character. */
194 RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
195@@ -3394,8 +3401,11 @@
196 }
197 else
198 shell_ungetc (peekc);
199- tflags |= LEX_HEREDELIM;
200- lex_firstind = -1;
201+ if (peekc != '<')
202+ {
203+ tflags |= LEX_HEREDELIM;
204+ lex_firstind = -1;
205+ }
206 continue;
207 }
208 else
209@@ -4248,7 +4258,7 @@
210 ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
211 (token_index == 0 && (parser_state&PST_COMPASSIGN))))
212 {
213- ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
214+ ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
215 if (ttok == &matched_pair_error)
216 return -1; /* Bail immediately. */
217 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
218@@ -4449,6 +4459,7 @@
219 case '}': /* XXX */
220 case AND_AND:
221 case BANG:
222+ case BAR_AND:
223 case DO:
224 case DONE:
225 case ELIF:
226diff -Naur bash-4.0.orig/pcomplete.c bash-4.0/pcomplete.c
227--- bash-4.0.orig/pcomplete.c 2009-02-01 14:12:31.000000000 -0800
228+++ bash-4.0/pcomplete.c 2009-02-27 08:56:48.837092332 -0800
229@@ -1032,6 +1032,7 @@
230 cmdlist = build_arg_list (funcname, text, lwords, cw);
231
232 pps = &ps;
233+ save_parser_state (pps);
234 begin_unwind_frame ("gen-shell-function-matches");
235 add_unwind_protect (restore_parser_state, (char *)pps);
236 add_unwind_protect (dispose_words, (char *)cmdlist);
237diff -Naur bash-4.0.orig/subst.c bash-4.0/subst.c
238--- bash-4.0.orig/subst.c 2009-01-28 11:34:12.000000000 -0800
239+++ bash-4.0/subst.c 2009-02-27 08:59:33.307629837 -0800
240@@ -222,6 +222,7 @@
241 static int skip_double_quoted __P((char *, size_t, int));
242 static char *extract_delimited_string __P((char *, int *, char *, char *, char *, int));
243 static char *extract_dollar_brace_string __P((char *, int *, int, int));
244+static int skip_matched_pair __P((const char *, int, int, int, int));
245
246 static char *pos_params __P((char *, int, int, int));
247
248@@ -1374,6 +1375,107 @@
249
250 #define CQ_RETURN(x) do { no_longjmp_on_fatal_error = 0; return (x); } while (0)
251
252+/* This function assumes s[i] == open; returns with s[ret] == close; used to
253+ parse array subscripts. FLAGS currently unused. */
254+static int
255+skip_matched_pair (string, start, open, close, flags)
256+ const char *string;
257+ int start, open, close, flags;
258+{
259+ int i, pass_next, backq, si, c, count;
260+ size_t slen;
261+ char *temp, *ss;
262+ DECLARE_MBSTATE;
263+
264+ slen = strlen (string + start) + start;
265+ no_longjmp_on_fatal_error = 1;
266+
267+ i = start + 1; /* skip over leading bracket */
268+ count = 1;
269+ pass_next = backq = 0;
270+ ss = (char *)string;
271+ while (c = string[i])
272+ {
273+ if (pass_next)
274+ {
275+ pass_next = 0;
276+ if (c == 0)
277+ CQ_RETURN(i);
278+ ADVANCE_CHAR (string, slen, i);
279+ continue;
280+ }
281+ else if (c == '\\')
282+ {
283+ pass_next = 1;
284+ i++;
285+ continue;
286+ }
287+ else if (backq)
288+ {
289+ if (c == '`')
290+ backq = 0;
291+ ADVANCE_CHAR (string, slen, i);
292+ continue;
293+ }
294+ else if (c == '`')
295+ {
296+ backq = 1;
297+ i++;
298+ continue;
299+ }
300+ else if (c == open)
301+ {
302+ count++;
303+ i++;
304+ continue;
305+ }
306+ else if (c == close)
307+ {
308+ count--;
309+ if (count == 0)
310+ break;
311+ i++;
312+ continue;
313+ }
314+ else if (c == '\'' || c == '"')
315+ {
316+ i = (c == '\'') ? skip_single_quoted (ss, slen, ++i)
317+ : skip_double_quoted (ss, slen, ++i);
318+ /* no increment, the skip functions increment past the closing quote. */
319+ }
320+ else if (c == '$' && (string[i+1] == LPAREN || string[i+1] == LBRACE))
321+ {
322+ si = i + 2;
323+ if (string[si] == '\0')
324+ CQ_RETURN(si);
325+
326+ if (string[i+1] == LPAREN)
327+ temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */
328+ else
329+ temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC);
330+ i = si;
331+ if (string[i] == '\0') /* don't increment i past EOS in loop */
332+ break;
333+ i++;
334+ continue;
335+ }
336+ else
337+ ADVANCE_CHAR (string, slen, i);
338+ }
339+
340+ CQ_RETURN(i);
341+}
342+
343+#if defined (ARRAY_VARS)
344+int
345+skipsubscript (string, start)
346+ const char *string;
347+ int start;
348+{
349+ return (skip_matched_pair (string, start, '[', ']', 0));
350+}
351+#endif
352+
353 /* Skip characters in STRING until we find a character in DELIMS, and return
354 the index of that character. START is the index into string at which we
355 begin. This is similar in spirit to strpbrk, but it returns an index into
356
Note: See TracBrowser for help on using the repository browser.