7 Bug-Reported-by: Clark J. Wang <dearvoid@gmail.com>
8 Bug-Reference-ID: <AANLkTikZ_rVV-frR8Fh0PzhXnMKnm5XsUR-F3qtPPs5G@mail.gmail.com>
9 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2011-02/msg00136.html
13 When using the pattern replacement and pattern removal word expansions, bash
14 miscalculates the possible match length in the presence of an unescaped left
15 bracket without a closing right bracket, resulting in a failure to match
18 Patch (apply with `patch -p0'):
20 *** ../bash-4.2-patched/lib/glob/gmisc.c 2011-02-05 16:11:17.000000000 -0500
21 --- lib/glob/gmisc.c 2011-02-18 23:53:42.000000000 -0500
26 ! wchar_t wc, *wbrack;
27 ! int matlen, t, in_cclass, in_collsym, in_equiv;
34 ! int matlen, bracklen, t, in_cclass, in_collsym, in_equiv;
40 /* scan for ending `]', skipping over embedded [:...:] */
46 /* scan for ending `]', skipping over embedded [:...:] */
54 ! matlen += wpat - wbrack - 1; /* incremented below */
63 else if (wc == L'[' && *wpat == L':') /* character class */
71 ! wpat--; /* back up to NUL */
77 ! /* *wpat == backslash-escaped character */
79 ! /* If the backslash or backslash-escape ends the string,
80 ! bail. The ++wpat skips over the backslash escape */
81 ! if (*wpat == 0 || *++wpat == 0)
87 else if (wc == L'[' && *wpat == L':') /* character class */
105 if (*wpat == L']') /* right bracket can appear as collating symbol */
113 if (*wpat == L']') /* right bracket can appear as collating symbol */
132 if (*wpat == L']') /* right bracket can appear as equivalence class */
140 if (*wpat == L']') /* right bracket can appear as equivalence class */
158 while ((wc = *wpat++) != L']');
159 matlen++; /* bracket expression can only match one char */
168 ! int matlen, t, in_cclass, in_collsym, in_equiv;
175 ! int matlen, bracklen, t, in_cclass, in_collsym, in_equiv;
181 /* scan for ending `]', skipping over embedded [:...:] */
187 /* scan for ending `]', skipping over embedded [:...:] */
195 ! matlen += pat - brack - 1; /* incremented below */
204 else if (c == '[' && *pat == ':') /* character class */
212 ! pat--; /* back up to NUL */
213 ! matlen += bracklen;
218 ! /* *pat == backslash-escaped character */
220 ! /* If the backslash or backslash-escape ends the string,
221 ! bail. The ++pat skips over the backslash escape */
222 ! if (*pat == 0 || *++pat == 0)
224 ! matlen += bracklen;
228 else if (c == '[' && *pat == ':') /* character class */
246 if (*pat == ']') /* right bracket can appear as collating symbol */
254 if (*pat == ']') /* right bracket can appear as collating symbol */
273 if (*pat == ']') /* right bracket can appear as equivalence class */
281 if (*pat == ']') /* right bracket can appear as equivalence class */
299 while ((c = *pat++) != ']');
300 matlen++; /* bracket expression can only match one char */
304 *** ../bash-4.2-patched/patchlevel.h Sat Jun 12 20:14:48 2010
305 --- patchlevel.h Thu Feb 24 21:41:34 2011
308 looks for to find the patch level (for the sccs version string). */
310 ! #define PATCHLEVEL 2
312 #endif /* _PATCHLEVEL_H_ */
314 looks for to find the patch level (for the sccs version string). */
316 ! #define PATCHLEVEL 3
318 #endif /* _PATCHLEVEL_H_ */