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
278
279
280
281
|
*** lib/fnmatch_loop.c.bak 2009-12-10 20:38:55.000000000 +0100
--- lib/fnmatch_loop.c 2009-12-11 11:55:04.000000000 +0100
***************
*** 1021,1040 ****
struct patternlist
{
struct patternlist *next;
CHAR str[1];
} *list = NULL;
struct patternlist **lastp = &list;
size_t pattern_len = STRLEN (pattern);
const CHAR *p;
const CHAR *rs;
enum { ALLOCA_LIMIT = 8000 };
/* Parse the pattern. Store the individual parts in the list. */
level = 0;
for (startp = p = pattern + 1; ; ++p)
if (*p == L_('\0'))
/* This is an invalid pattern. */
! return -1;
else if (*p == L_('['))
{
/* Handle brackets special. */
--- 1021,1046 ----
struct patternlist
{
struct patternlist *next;
+ int malloced;
CHAR str[1];
} *list = NULL;
struct patternlist **lastp = &list;
size_t pattern_len = STRLEN (pattern);
const CHAR *p;
const CHAR *rs;
+ #if HAVE_ALLOCA || defined _LIBC
enum { ALLOCA_LIMIT = 8000 };
+ #else
+ enum { ALLOCA_LIMIT = 0 };
+ #endif
+ int retval;
/* Parse the pattern. Store the individual parts in the list. */
level = 0;
for (startp = p = pattern + 1; ; ++p)
if (*p == L_('\0'))
/* This is an invalid pattern. */
! goto failed;
else if (*p == L_('['))
{
/* Handle brackets special. */
***************
*** 1052,1058 ****
while (*p != L_(']'))
if (*p++ == L_('\0'))
/* This is no valid pattern. */
! return -1;
}
else if ((*p == L_('?') || *p == L_('*') || *p == L_('+') || *p == L_('@')
|| *p == L_('!')) && p[1] == L_('('))
--- 1058,1064 ----
while (*p != L_(']'))
if (*p++ == L_('\0'))
/* This is no valid pattern. */
! goto failed;
}
else if ((*p == L_('?') || *p == L_('*') || *p == L_('+') || *p == L_('@')
|| *p == L_('!')) && p[1] == L_('('))
***************
*** 1075,1085 ****
plensize = plen * sizeof (CHAR); \
newpsize = offsetof (struct patternlist, str) + plensize; \
if ((size_t) -1 / sizeof (CHAR) < plen \
! || newpsize < offsetof (struct patternlist, str) \
! || ALLOCA_LIMIT <= newpsize) \
! return -1; \
! newp = (struct patternlist *) alloca (newpsize); \
! *((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L_('\0'); \
newp->next = NULL; \
*lastp = newp; \
lastp = &newp->next
--- 1081,1101 ----
plensize = plen * sizeof (CHAR); \
newpsize = offsetof (struct patternlist, str) + plensize; \
if ((size_t) -1 / sizeof (CHAR) < plen \
! || newpsize < offsetof (struct patternlist, str)) \
! goto failed; \
! if (newpsize < ALLOCA_LIMIT) \
! { \
! newp = (struct patternlist *) alloca (newpsize); \
! newp->malloced = 0; \
! } \
! else \
! { \
! newp = (struct patternlist *) malloc (newpsize); \
! if (!newp) \
! goto failed; \
! newp->malloced = 1; \
! } \
! *((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L_('\0'); \
newp->next = NULL; \
*lastp = newp; \
lastp = &newp->next
***************
*** 1103,1114 ****
{
case L_('*'):
if (FCT (p, string, string_end, no_leading_period, flags) == 0)
! return 0;
/* FALLTHROUGH */
case L_('+'):
do
{
for (rs = string; rs <= string_end; ++rs)
/* First match the prefix with the current pattern with the
current pattern. */
--- 1119,1135 ----
{
case L_('*'):
if (FCT (p, string, string_end, no_leading_period, flags) == 0)
! {
! retval = 0;
! goto done;
! }
/* FALLTHROUGH */
case L_('+'):
do
{
+ struct patternlist *next;
+
for (rs = string; rs <= string_end; ++rs)
/* First match the prefix with the current pattern with the
current pattern. */
***************
*** 1130,1160 ****
: rs[-1] == '/' && NO_LEADING_PERIOD (flags),
flags & FNM_FILE_NAME
? flags : flags & ~FNM_PERIOD) == 0)))
! /* It worked. Signal success. */
! return 0;
}
! while ((list = list->next) != NULL);
/* None of the patterns lead to a match. */
return FNM_NOMATCH;
case L_('?'):
if (FCT (p, string, string_end, no_leading_period, flags) == 0)
! return 0;
/* FALLTHROUGH */
case L_('@'):
do
! /* I cannot believe it but 'strcat' is actually acceptable
! here. Match the entire string with the prefix from the
! pattern list and the rest of the pattern following the
! pattern list. */
! if (FCT (STRCAT (list->str, p), string, string_end,
! no_leading_period,
! flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0)
! /* It worked. Signal success. */
! return 0;
! while ((list = list->next) != NULL);
/* None of the patterns lead to a match. */
return FNM_NOMATCH;
--- 1151,1204 ----
: rs[-1] == '/' && NO_LEADING_PERIOD (flags),
flags & FNM_FILE_NAME
? flags : flags & ~FNM_PERIOD) == 0)))
! {
! /* It worked. Signal success. */
! retval = 0;
! goto done;
! }
!
! next = list->next;
! if (list->malloced)
! free (list);
! list = next;
}
! while (list != NULL);
/* None of the patterns lead to a match. */
return FNM_NOMATCH;
case L_('?'):
if (FCT (p, string, string_end, no_leading_period, flags) == 0)
! {
! retval = 0;
! goto done;
! }
/* FALLTHROUGH */
case L_('@'):
do
! {
! struct patternlist *next;
!
! /* I cannot believe it but 'strcat' is actually acceptable
! here. Match the entire string with the prefix from the
! pattern list and the rest of the pattern following the
! pattern list. */
! if (FCT (STRCAT (list->str, p), string, string_end,
! no_leading_period,
! flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0)
! {
! /* It worked. Signal success. */
! retval = 0;
! goto done;
! }
!
! next = list->next;
! if (list->malloced)
! free (list);
! list = next;
! }
! while (list != NULL);
/* None of the patterns lead to a match. */
return FNM_NOMATCH;
***************
*** 1177,1196 ****
: rs[-1] == '/' && NO_LEADING_PERIOD (flags),
flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD)
== 0))
! /* This is successful. */
! return 0;
}
/* None of the patterns together with the rest of the pattern
lead to a match. */
! return FNM_NOMATCH;
default:
assert (! "Invalid extended matching operator");
break;
}
! return -1;
}
--- 1221,1255 ----
: rs[-1] == '/' && NO_LEADING_PERIOD (flags),
flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD)
== 0))
! {
! /* This is successful. */
! retval = 0;
! goto done;
! }
}
/* None of the patterns together with the rest of the pattern
lead to a match. */
! retval = FNM_NOMATCH;
! goto done;
default:
assert (! "Invalid extended matching operator");
break;
}
! failed:
! retval = -1;
! done:
! while (list != NULL)
! {
! struct patternlist *next = list->next;
!
! if (list->malloced)
! free (list);
! list = next;
! }
! return retval;
}
|