1 # DP: bash-4.2 upstream patch 003
9 Bug-Reported-by: Clark J. Wang <dearvoid@gmail.com>
10 Bug-Reference-ID: <AANLkTikZ_rVV-frR8Fh0PzhXnMKnm5XsUR-F3qtPPs5G@mail.gmail.com>
11 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2011-02/msg00136.html
15 When using the pattern replacement and pattern removal word expansions, bash
16 miscalculates the possible match length in the presence of an unescaped left
17 bracket without a closing right bracket, resulting in a failure to match
20 Patch (apply with `patch -p0'):
22 --- a/bash/lib/glob/gmisc.c
23 +++ b/bash/lib/glob/gmisc.c
28 - wchar_t wc, *wbrack;
29 - int matlen, t, in_cclass, in_collsym, in_equiv;
31 + int matlen, bracklen, t, in_cclass, in_collsym, in_equiv;
38 /* scan for ending `]', skipping over embedded [:...:] */
46 - matlen += wpat - wbrack - 1; /* incremented below */
48 + wpat--; /* back up to NUL */
57 + /* *wpat == backslash-escaped character */
59 + /* If the backslash or backslash-escape ends the string,
60 + bail. The ++wpat skips over the backslash escape */
61 + if (*wpat == 0 || *++wpat == 0)
67 else if (wc == L'[' && *wpat == L':') /* character class */
73 else if (in_cclass && wc == L':' && *wpat == L']')
79 else if (wc == L'[' && *wpat == L'.') /* collating symbol */
83 if (*wpat == L']') /* right bracket can appear as collating symbol */
91 else if (in_collsym && wc == L'.' && *wpat == L']')
97 else if (wc == L'[' && *wpat == L'=') /* equivalence class */
101 if (*wpat == L']') /* right bracket can appear as equivalence class */
109 else if (in_equiv && wc == L'=' && *wpat == L']')
118 while ((wc = *wpat++) != L']');
119 matlen++; /* bracket expression can only match one char */
129 - int matlen, t, in_cclass, in_collsym, in_equiv;
131 + int matlen, bracklen, t, in_cclass, in_collsym, in_equiv;
135 @@ -254,58 +276,80 @@
138 /* scan for ending `]', skipping over embedded [:...:] */
146 - matlen += pat - brack - 1; /* incremented below */
148 + pat--; /* back up to NUL */
149 + matlen += bracklen;
157 + /* *pat == backslash-escaped character */
159 + /* If the backslash or backslash-escape ends the string,
160 + bail. The ++pat skips over the backslash escape */
161 + if (*pat == 0 || *++pat == 0)
163 + matlen += bracklen;
167 else if (c == '[' && *pat == ':') /* character class */
173 else if (in_cclass && c == ':' && *pat == ']')
179 else if (c == '[' && *pat == '.') /* collating symbol */
183 if (*pat == ']') /* right bracket can appear as collating symbol */
191 else if (in_collsym && c == '.' && *pat == ']')
197 else if (c == '[' && *pat == '=') /* equivalence class */
201 if (*pat == ']') /* right bracket can appear as equivalence class */
209 else if (in_equiv && c == '=' && *pat == ']')
218 while ((c = *pat++) != ']');
219 matlen++; /* bracket expression can only match one char */
224 --- a/bash/patchlevel.h
225 +++ b/bash/patchlevel.h
227 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
228 looks for to find the patch level (for the sccs version string). */
230 -#define PATCHLEVEL 2
231 +#define PATCHLEVEL 3
233 #endif /* _PATCHLEVEL_H_ */