rugged 1.9.4 → 1.9.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/CMakeLists.txt +1 -1
  4. data/vendor/libgit2/COPYING +83 -11
  5. data/vendor/libgit2/cmake/SelectRegex.cmake +8 -3
  6. data/vendor/libgit2/deps/pcre2/CMakeLists.txt +110 -0
  7. data/vendor/libgit2/deps/pcre2/LICENCE.md +104 -0
  8. data/vendor/libgit2/deps/pcre2/config.h.in +54 -0
  9. data/vendor/libgit2/deps/pcre2/pcre2.h +1079 -0
  10. data/vendor/libgit2/deps/pcre2/pcre2_auto_possess.c +1416 -0
  11. data/vendor/libgit2/deps/{pcre/pcre_chartables.c → pcre2/pcre2_chartables.c} +41 -47
  12. data/vendor/libgit2/deps/{pcre/pcre_ord2utf8.c → pcre2/pcre2_chkdint.c} +36 -36
  13. data/vendor/libgit2/deps/pcre2/pcre2_compile.c +11345 -0
  14. data/vendor/libgit2/deps/pcre2/pcre2_compile.h +356 -0
  15. data/vendor/libgit2/deps/pcre2/pcre2_compile_cgroup.c +632 -0
  16. data/vendor/libgit2/deps/pcre2/pcre2_compile_class.c +2777 -0
  17. data/vendor/libgit2/deps/pcre2/pcre2_config.c +250 -0
  18. data/vendor/libgit2/deps/pcre2/pcre2_context.c +557 -0
  19. data/vendor/libgit2/deps/pcre2/pcre2_convert.c +1263 -0
  20. data/vendor/libgit2/deps/{pcre/pcre_dfa_exec.c → pcre2/pcre2_dfa_match.c} +1402 -943
  21. data/vendor/libgit2/deps/pcre2/pcre2_error.c +384 -0
  22. data/vendor/libgit2/deps/pcre2/pcre2_extuni.c +159 -0
  23. data/vendor/libgit2/deps/pcre2/pcre2_find_bracket.c +217 -0
  24. data/vendor/libgit2/deps/pcre2/pcre2_fuzzsupport.c +844 -0
  25. data/vendor/libgit2/deps/pcre2/pcre2_internal.h +2353 -0
  26. data/vendor/libgit2/deps/pcre2/pcre2_intmodedep.h +1044 -0
  27. data/vendor/libgit2/deps/pcre2/pcre2_maketables.c +177 -0
  28. data/vendor/libgit2/deps/pcre2/pcre2_match.c +8244 -0
  29. data/vendor/libgit2/deps/pcre2/pcre2_match_data.c +184 -0
  30. data/vendor/libgit2/deps/pcre2/pcre2_match_next.c +171 -0
  31. data/vendor/libgit2/deps/{pcre/pcre_newline.c → pcre2/pcre2_newline.c} +92 -63
  32. data/vendor/libgit2/deps/{pcre/pcre_refcount.c → pcre2/pcre2_ord2utf.c} +64 -38
  33. data/vendor/libgit2/deps/pcre2/pcre2_pattern_info.c +430 -0
  34. data/vendor/libgit2/deps/pcre2/pcre2_printint_inc.h +1098 -0
  35. data/vendor/libgit2/deps/pcre2/pcre2_script_run.c +344 -0
  36. data/vendor/libgit2/deps/pcre2/pcre2_serialize.c +284 -0
  37. data/vendor/libgit2/deps/pcre2/pcre2_string_utils.c +199 -0
  38. data/vendor/libgit2/deps/pcre2/pcre2_study.c +2087 -0
  39. data/vendor/libgit2/deps/pcre2/pcre2_substitute.c +1761 -0
  40. data/vendor/libgit2/deps/pcre2/pcre2_substring.c +553 -0
  41. data/vendor/libgit2/deps/pcre2/pcre2_tables.c +310 -0
  42. data/vendor/libgit2/deps/pcre2/pcre2_ucd.c +5805 -0
  43. data/vendor/libgit2/deps/pcre2/pcre2_ucp.h +408 -0
  44. data/vendor/libgit2/deps/pcre2/pcre2_ucptables_inc.h +1596 -0
  45. data/vendor/libgit2/deps/pcre2/pcre2_util.h +179 -0
  46. data/vendor/libgit2/deps/pcre2/pcre2_valid_utf.c +397 -0
  47. data/vendor/libgit2/deps/pcre2/pcre2_xclass.c +547 -0
  48. data/vendor/libgit2/include/git2/common.h +13 -1
  49. data/vendor/libgit2/include/git2/version.h +2 -2
  50. data/vendor/libgit2/src/libgit2/blame.c +6 -0
  51. data/vendor/libgit2/src/libgit2/delta.c +8 -0
  52. data/vendor/libgit2/src/libgit2/indexer.c +3 -2
  53. data/vendor/libgit2/src/libgit2/settings.c +9 -0
  54. data/vendor/libgit2/src/libgit2/streams/openssl.c +4 -1
  55. data/vendor/libgit2/src/libgit2/submodule.c +77 -12
  56. data/vendor/libgit2/src/libgit2/transports/http.c +4 -4
  57. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +2 -1
  58. data/vendor/libgit2/src/util/fs_path.h +10 -10
  59. data/vendor/libgit2/src/util/regexp.c +27 -12
  60. data/vendor/libgit2/src/util/regexp.h +7 -2
  61. metadata +44 -37
  62. data/vendor/libgit2/deps/pcre/CMakeLists.txt +0 -140
  63. data/vendor/libgit2/deps/pcre/COPYING +0 -5
  64. data/vendor/libgit2/deps/pcre/LICENCE +0 -93
  65. data/vendor/libgit2/deps/pcre/cmake/COPYING-CMAKE-SCRIPTS +0 -22
  66. data/vendor/libgit2/deps/pcre/cmake/FindEditline.cmake +0 -17
  67. data/vendor/libgit2/deps/pcre/cmake/FindPackageHandleStandardArgs.cmake +0 -58
  68. data/vendor/libgit2/deps/pcre/cmake/FindReadline.cmake +0 -29
  69. data/vendor/libgit2/deps/pcre/config.h.in +0 -57
  70. data/vendor/libgit2/deps/pcre/pcre.h +0 -641
  71. data/vendor/libgit2/deps/pcre/pcre_byte_order.c +0 -319
  72. data/vendor/libgit2/deps/pcre/pcre_compile.c +0 -9815
  73. data/vendor/libgit2/deps/pcre/pcre_config.c +0 -190
  74. data/vendor/libgit2/deps/pcre/pcre_exec.c +0 -7173
  75. data/vendor/libgit2/deps/pcre/pcre_fullinfo.c +0 -245
  76. data/vendor/libgit2/deps/pcre/pcre_get.c +0 -669
  77. data/vendor/libgit2/deps/pcre/pcre_globals.c +0 -86
  78. data/vendor/libgit2/deps/pcre/pcre_internal.h +0 -2787
  79. data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +0 -11913
  80. data/vendor/libgit2/deps/pcre/pcre_maketables.c +0 -156
  81. data/vendor/libgit2/deps/pcre/pcre_printint.c +0 -834
  82. data/vendor/libgit2/deps/pcre/pcre_string_utils.c +0 -211
  83. data/vendor/libgit2/deps/pcre/pcre_study.c +0 -1686
  84. data/vendor/libgit2/deps/pcre/pcre_tables.c +0 -727
  85. data/vendor/libgit2/deps/pcre/pcre_ucd.c +0 -3644
  86. data/vendor/libgit2/deps/pcre/pcre_valid_utf8.c +0 -301
  87. data/vendor/libgit2/deps/pcre/pcre_version.c +0 -98
  88. data/vendor/libgit2/deps/pcre/pcre_xclass.c +0 -268
  89. data/vendor/libgit2/deps/pcre/pcreposix.c +0 -420
  90. data/vendor/libgit2/deps/pcre/pcreposix.h +0 -117
  91. data/vendor/libgit2/deps/pcre/ucp.h +0 -224
@@ -0,0 +1,1263 @@
1
+ /*************************************************
2
+ * Perl-Compatible Regular Expressions *
3
+ *************************************************/
4
+
5
+ /* PCRE is a library of functions to support regular expressions whose syntax
6
+ and semantics are as close as possible to those of the Perl 5 language.
7
+
8
+ Written by Philip Hazel
9
+ Original API code Copyright (c) 1997-2012 University of Cambridge
10
+ New API code Copyright (c) 2016-2024 University of Cambridge
11
+
12
+ -----------------------------------------------------------------------------
13
+ Redistribution and use in source and binary forms, with or without
14
+ modification, are permitted provided that the following conditions are met:
15
+
16
+ * Redistributions of source code must retain the above copyright notice,
17
+ this list of conditions and the following disclaimer.
18
+
19
+ * Redistributions in binary form must reproduce the above copyright
20
+ notice, this list of conditions and the following disclaimer in the
21
+ documentation and/or other materials provided with the distribution.
22
+
23
+ * Neither the name of the University of Cambridge nor the names of its
24
+ contributors may be used to endorse or promote products derived from
25
+ this software without specific prior written permission.
26
+
27
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
+ POSSIBILITY OF SUCH DAMAGE.
38
+ -----------------------------------------------------------------------------
39
+ */
40
+
41
+
42
+ #include "pcre2_internal.h"
43
+
44
+
45
+
46
+ #define TYPE_OPTIONS (PCRE2_CONVERT_GLOB| \
47
+ PCRE2_CONVERT_POSIX_BASIC|PCRE2_CONVERT_POSIX_EXTENDED)
48
+
49
+ #define ALL_OPTIONS (PCRE2_CONVERT_UTF|PCRE2_CONVERT_NO_UTF_CHECK| \
50
+ PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR| \
51
+ PCRE2_CONVERT_GLOB_NO_STARSTAR| \
52
+ TYPE_OPTIONS)
53
+
54
+ #define DUMMY_BUFFER_SIZE 100
55
+
56
+ /* Generated pattern fragments */
57
+
58
+ #define STR_BACKSLASH_A STR_BACKSLASH STR_A
59
+ #define STR_BACKSLASH_z STR_BACKSLASH STR_z
60
+ #define STR_COLON_RIGHT_SQUARE_BRACKET STR_COLON STR_RIGHT_SQUARE_BRACKET
61
+ #define STR_DOT_STAR_LOOKBEHIND STR_DOT STR_ASTERISK STR_LEFT_PARENTHESIS STR_QUESTION_MARK STR_LESS_THAN_SIGN STR_EQUALS_SIGN
62
+ #define STR_LOOKAHEAD_NOT_DOT STR_LEFT_PARENTHESIS STR_QUESTION_MARK STR_EXCLAMATION_MARK STR_BACKSLASH STR_DOT STR_RIGHT_PARENTHESIS
63
+ #define STR_QUERY_s STR_LEFT_PARENTHESIS STR_QUESTION_MARK STR_s STR_RIGHT_PARENTHESIS
64
+ #define STR_STAR_NUL STR_LEFT_PARENTHESIS STR_ASTERISK STR_N STR_U STR_L STR_RIGHT_PARENTHESIS
65
+
66
+ /* States for POSIX processing */
67
+
68
+ enum { POSIX_START_REGEX, POSIX_ANCHORED, POSIX_NOT_BRACKET,
69
+ POSIX_CLASS_NOT_STARTED, POSIX_CLASS_STARTING, POSIX_CLASS_STARTED };
70
+
71
+ /* Macro to add a character string to the output buffer, checking for overflow. */
72
+
73
+ #define PUTCHARS(string) \
74
+ { \
75
+ const char *s; \
76
+ for (s = string; *s != 0; s++) \
77
+ { \
78
+ if (p >= endp) return PCRE2_ERROR_NOMEMORY; \
79
+ *p++ = *s; \
80
+ } \
81
+ }
82
+
83
+ /* Macro to check for lowercase characters. */
84
+
85
+ #ifdef EBCDIC
86
+ #define ISLOWER(c) (((c) >= CHAR_a && (c) <= CHAR_i) || \
87
+ ((c) >= CHAR_j && (c) <= CHAR_r) || \
88
+ ((c) >= CHAR_s && (c) <= CHAR_z))
89
+ #else
90
+ #define ISLOWER(c) ((c) >= CHAR_a && (c) <= CHAR_z)
91
+ #endif
92
+
93
+ /* Literals that must be escaped: \ ? * + | . ^ $ { } [ ] ( ) */
94
+
95
+ static const char *pcre2_escaped_literals =
96
+ STR_BACKSLASH STR_QUESTION_MARK STR_ASTERISK STR_PLUS
97
+ STR_VERTICAL_LINE STR_DOT STR_CIRCUMFLEX_ACCENT STR_DOLLAR_SIGN
98
+ STR_LEFT_CURLY_BRACKET STR_RIGHT_CURLY_BRACKET
99
+ STR_LEFT_SQUARE_BRACKET STR_RIGHT_SQUARE_BRACKET
100
+ STR_LEFT_PARENTHESIS STR_RIGHT_PARENTHESIS;
101
+
102
+ /* Recognized escaped metacharacters in POSIX basic patterns. */
103
+
104
+ static const char *posix_meta_escapes =
105
+ STR_LEFT_PARENTHESIS STR_RIGHT_PARENTHESIS
106
+ STR_LEFT_CURLY_BRACKET STR_RIGHT_CURLY_BRACKET
107
+ STR_1 STR_2 STR_3 STR_4 STR_5 STR_6 STR_7 STR_8 STR_9;
108
+
109
+ /* Recognized POSIX classes, colon-separated. */
110
+
111
+ static const char *posix_classes =
112
+ STR_a STR_l STR_p STR_h STR_a STR_COLON
113
+ STR_l STR_o STR_w STR_e STR_r STR_COLON
114
+ STR_u STR_p STR_p STR_e STR_r STR_COLON
115
+ STR_a STR_l STR_n STR_u STR_m STR_COLON
116
+ STR_a STR_s STR_c STR_i STR_i STR_COLON
117
+ STR_b STR_l STR_a STR_n STR_k STR_COLON
118
+ STR_c STR_n STR_t STR_r STR_l STR_COLON
119
+ STR_d STR_i STR_g STR_i STR_t STR_COLON
120
+ STR_g STR_r STR_a STR_p STR_h STR_COLON
121
+ STR_p STR_r STR_i STR_n STR_t STR_COLON
122
+ STR_p STR_u STR_n STR_c STR_t STR_COLON
123
+ STR_s STR_p STR_a STR_c STR_e STR_COLON
124
+ STR_w STR_o STR_r STR_d STR_COLON
125
+ STR_x STR_d STR_i STR_g STR_i STR_t STR_COLON;
126
+
127
+
128
+
129
+ /*************************************************
130
+ * Convert a POSIX pattern *
131
+ *************************************************/
132
+
133
+ /* This function handles both basic and extended POSIX patterns.
134
+
135
+ Arguments:
136
+ pattype the pattern type
137
+ pattern the pattern
138
+ plength length in code units
139
+ utf TRUE if UTF
140
+ use_buffer where to put the output
141
+ use_length length of use_buffer
142
+ bufflenptr where to put the used length
143
+ dummyrun TRUE if a dummy run
144
+ ccontext the convert context
145
+
146
+ Returns: 0 => success
147
+ !0 => error code
148
+ */
149
+
150
+ static int
151
+ convert_posix(uint32_t pattype, PCRE2_SPTR pattern, PCRE2_SIZE plength,
152
+ BOOL utf, PCRE2_UCHAR *use_buffer, PCRE2_SIZE use_length,
153
+ PCRE2_SIZE *bufflenptr, BOOL dummyrun, pcre2_convert_context *ccontext)
154
+ {
155
+ PCRE2_SPTR posix = pattern;
156
+ PCRE2_UCHAR *p = use_buffer;
157
+ PCRE2_UCHAR *pp = p;
158
+ PCRE2_UCHAR *endp = p + use_length - 1; /* Allow for trailing zero */
159
+ PCRE2_SIZE convlength = 0;
160
+
161
+ uint32_t bracount = 0;
162
+ uint32_t posix_state = POSIX_START_REGEX;
163
+ uint32_t lastspecial = 0;
164
+ BOOL extended = (pattype & PCRE2_CONVERT_POSIX_EXTENDED) != 0;
165
+ BOOL nextisliteral = FALSE;
166
+
167
+ (void)utf; /* Not used when Unicode not supported */
168
+ (void)ccontext; /* Not currently used */
169
+
170
+ /* Initialize default for error offset as end of input. */
171
+
172
+ *bufflenptr = plength;
173
+ PUTCHARS(STR_STAR_NUL);
174
+
175
+ /* Now scan the input. */
176
+
177
+ while (plength > 0)
178
+ {
179
+ uint32_t c, sc;
180
+ int clength = 1;
181
+
182
+ /* Add in the length of the last item, then, if in the dummy run, pull the
183
+ pointer back to the start of the (temporary) buffer and then remember the
184
+ start of the next item. */
185
+
186
+ convlength += p - pp;
187
+ if (dummyrun) p = use_buffer;
188
+ pp = p;
189
+
190
+ /* Pick up the next character */
191
+
192
+ #ifndef SUPPORT_UNICODE
193
+ c = *posix;
194
+ #else
195
+ GETCHARLENTEST(c, posix, clength);
196
+ #endif
197
+ posix += clength;
198
+ plength -= clength;
199
+
200
+ sc = nextisliteral? 0 : c;
201
+ nextisliteral = FALSE;
202
+
203
+ /* Handle a character within a class. */
204
+
205
+ if (posix_state >= POSIX_CLASS_NOT_STARTED)
206
+ {
207
+ if (c == CHAR_RIGHT_SQUARE_BRACKET)
208
+ {
209
+ PUTCHARS(STR_RIGHT_SQUARE_BRACKET);
210
+ posix_state = POSIX_NOT_BRACKET;
211
+ }
212
+
213
+ /* Not the end of the class */
214
+
215
+ else
216
+ {
217
+ switch (posix_state)
218
+ {
219
+ case POSIX_CLASS_STARTED:
220
+ if (ISLOWER(c)) break; /* Remain in started state */
221
+ posix_state = POSIX_CLASS_NOT_STARTED;
222
+ if (c == CHAR_COLON && plength > 0 &&
223
+ *posix == CHAR_RIGHT_SQUARE_BRACKET)
224
+ {
225
+ PUTCHARS(STR_COLON_RIGHT_SQUARE_BRACKET);
226
+ plength--;
227
+ posix++;
228
+ continue; /* With next character after :] */
229
+ }
230
+ PCRE2_FALLTHROUGH /* Fall through */
231
+
232
+ case POSIX_CLASS_NOT_STARTED:
233
+ if (c == CHAR_LEFT_SQUARE_BRACKET)
234
+ posix_state = POSIX_CLASS_STARTING;
235
+ break;
236
+
237
+ case POSIX_CLASS_STARTING:
238
+ if (c == CHAR_COLON) posix_state = POSIX_CLASS_STARTED;
239
+ break;
240
+ }
241
+
242
+ if (c == CHAR_BACKSLASH) PUTCHARS(STR_BACKSLASH);
243
+ if (p + clength > endp) return PCRE2_ERROR_NOMEMORY;
244
+ memcpy(p, posix - clength, CU2BYTES(clength));
245
+ p += clength;
246
+ }
247
+ }
248
+
249
+ /* Handle a character not within a class. */
250
+
251
+ else switch(sc)
252
+ {
253
+ case CHAR_LEFT_SQUARE_BRACKET:
254
+ PUTCHARS(STR_LEFT_SQUARE_BRACKET);
255
+
256
+ #ifdef NEVER
257
+ /* We could handle special cases [[:<:]] and [[:>:]] (which PCRE does
258
+ support) but they are not part of POSIX 1003.1. */
259
+
260
+ if (plength >= 6)
261
+ {
262
+ if (posix[0] == CHAR_LEFT_SQUARE_BRACKET &&
263
+ posix[1] == CHAR_COLON &&
264
+ (posix[2] == CHAR_LESS_THAN_SIGN ||
265
+ posix[2] == CHAR_GREATER_THAN_SIGN) &&
266
+ posix[3] == CHAR_COLON &&
267
+ posix[4] == CHAR_RIGHT_SQUARE_BRACKET &&
268
+ posix[5] == CHAR_RIGHT_SQUARE_BRACKET)
269
+ {
270
+ if (p + 6 > endp) return PCRE2_ERROR_NOMEMORY;
271
+ memcpy(p, posix, CU2BYTES(6));
272
+ p += 6;
273
+ posix += 6;
274
+ plength -= 6;
275
+ continue; /* With next character */
276
+ }
277
+ }
278
+ #endif
279
+
280
+ /* Handle start of "normal" character classes */
281
+
282
+ posix_state = POSIX_CLASS_NOT_STARTED;
283
+
284
+ /* Handle ^ and ] as first characters */
285
+
286
+ if (plength > 0)
287
+ {
288
+ if (*posix == CHAR_CIRCUMFLEX_ACCENT)
289
+ {
290
+ posix++;
291
+ plength--;
292
+ PUTCHARS(STR_CIRCUMFLEX_ACCENT);
293
+ }
294
+ if (plength > 0 && *posix == CHAR_RIGHT_SQUARE_BRACKET)
295
+ {
296
+ posix++;
297
+ plength--;
298
+ PUTCHARS(STR_RIGHT_SQUARE_BRACKET);
299
+ }
300
+ }
301
+ break;
302
+
303
+ case CHAR_BACKSLASH:
304
+ if (plength == 0) return PCRE2_ERROR_END_BACKSLASH;
305
+ if (extended) nextisliteral = TRUE; else
306
+ {
307
+ if (*posix < 255 && strchr(posix_meta_escapes, *posix) != NULL)
308
+ {
309
+ if (*posix >= CHAR_0 && *posix <= CHAR_9) PUTCHARS(STR_BACKSLASH);
310
+ if (p + 1 > endp) return PCRE2_ERROR_NOMEMORY;
311
+ lastspecial = *p++ = *posix++;
312
+ plength--;
313
+ }
314
+ else nextisliteral = TRUE;
315
+ }
316
+ break;
317
+
318
+ case CHAR_RIGHT_PARENTHESIS:
319
+ if (!extended || bracount == 0) goto ESCAPE_LITERAL;
320
+ bracount--;
321
+ goto COPY_SPECIAL;
322
+
323
+ case CHAR_LEFT_PARENTHESIS:
324
+ bracount++;
325
+ PCRE2_FALLTHROUGH /* Fall through */
326
+
327
+ case CHAR_QUESTION_MARK:
328
+ case CHAR_PLUS:
329
+ case CHAR_LEFT_CURLY_BRACKET:
330
+ case CHAR_RIGHT_CURLY_BRACKET:
331
+ case CHAR_VERTICAL_LINE:
332
+ if (!extended) goto ESCAPE_LITERAL;
333
+ PCRE2_FALLTHROUGH /* Fall through */
334
+
335
+ case CHAR_DOT:
336
+ case CHAR_DOLLAR_SIGN:
337
+ posix_state = POSIX_NOT_BRACKET;
338
+ COPY_SPECIAL:
339
+ lastspecial = c;
340
+ if (p + 1 > endp) return PCRE2_ERROR_NOMEMORY;
341
+ *p++ = c;
342
+ break;
343
+
344
+ case CHAR_ASTERISK:
345
+ if (lastspecial != CHAR_ASTERISK)
346
+ {
347
+ if (!extended && (posix_state < POSIX_NOT_BRACKET ||
348
+ lastspecial == CHAR_LEFT_PARENTHESIS))
349
+ goto ESCAPE_LITERAL;
350
+ goto COPY_SPECIAL;
351
+ }
352
+ break; /* Ignore second and subsequent asterisks */
353
+
354
+ case CHAR_CIRCUMFLEX_ACCENT:
355
+ if (extended) goto COPY_SPECIAL;
356
+ if (posix_state == POSIX_START_REGEX ||
357
+ lastspecial == CHAR_LEFT_PARENTHESIS)
358
+ {
359
+ posix_state = POSIX_ANCHORED;
360
+ goto COPY_SPECIAL;
361
+ }
362
+ PCRE2_FALLTHROUGH /* Fall through */
363
+
364
+ default:
365
+ if (c < 255 && strchr(pcre2_escaped_literals, c) != NULL)
366
+ {
367
+ ESCAPE_LITERAL:
368
+ PUTCHARS(STR_BACKSLASH);
369
+ }
370
+ lastspecial = 0xff; /* Indicates nothing special */
371
+ if (p + clength > endp) return PCRE2_ERROR_NOMEMORY;
372
+ memcpy(p, posix - clength, CU2BYTES(clength));
373
+ p += clength;
374
+ posix_state = POSIX_NOT_BRACKET;
375
+ break;
376
+ }
377
+ }
378
+
379
+ if (posix_state >= POSIX_CLASS_NOT_STARTED)
380
+ return PCRE2_ERROR_MISSING_SQUARE_BRACKET;
381
+ convlength += p - pp; /* Final segment */
382
+ *bufflenptr = convlength;
383
+ *p++ = 0;
384
+ return 0;
385
+ }
386
+
387
+
388
+ /*************************************************
389
+ * Convert a glob pattern *
390
+ *************************************************/
391
+
392
+ /* Context for writing the output into a buffer. */
393
+
394
+ typedef struct pcre2_output_context {
395
+ PCRE2_UCHAR *output; /* current output position */
396
+ PCRE2_SPTR output_end; /* output end */
397
+ PCRE2_SIZE output_size; /* size of the output */
398
+ uint8_t out_str[8]; /* string copied to the output */
399
+ } pcre2_output_context;
400
+
401
+
402
+ /* Write a character into the output.
403
+
404
+ Arguments:
405
+ out output context
406
+ chr the next character
407
+ */
408
+
409
+ static void
410
+ convert_glob_write(pcre2_output_context *out, PCRE2_UCHAR chr)
411
+ {
412
+ out->output_size++;
413
+
414
+ if (out->output < out->output_end)
415
+ *out->output++ = chr;
416
+ }
417
+
418
+
419
+ /* Write a string into the output.
420
+
421
+ Arguments:
422
+ out output context
423
+ length length of out->out_str
424
+ */
425
+
426
+ static void
427
+ convert_glob_write_str(pcre2_output_context *out, PCRE2_SIZE length)
428
+ {
429
+ uint8_t *out_str = out->out_str;
430
+ PCRE2_UCHAR *output = out->output;
431
+ PCRE2_SPTR output_end = out->output_end;
432
+ PCRE2_SIZE output_size = out->output_size;
433
+
434
+ do
435
+ {
436
+ output_size++;
437
+
438
+ if (output < output_end)
439
+ *output++ = *out_str++;
440
+ }
441
+ while (--length != 0);
442
+
443
+ out->output = output;
444
+ out->output_size = output_size;
445
+ }
446
+
447
+
448
+ /* Prints the separator into the output.
449
+
450
+ Arguments:
451
+ out output context
452
+ separator glob separator
453
+ with_escape backslash is needed before separator
454
+ */
455
+
456
+ static void
457
+ convert_glob_print_separator(pcre2_output_context *out,
458
+ PCRE2_UCHAR separator, BOOL with_escape)
459
+ {
460
+ if (with_escape)
461
+ convert_glob_write(out, CHAR_BACKSLASH);
462
+
463
+ convert_glob_write(out, separator);
464
+ }
465
+
466
+
467
+ /* Prints a wildcard into the output.
468
+
469
+ Arguments:
470
+ out output context
471
+ separator glob separator
472
+ with_escape backslash is needed before separator
473
+ */
474
+
475
+ static void
476
+ convert_glob_print_wildcard(pcre2_output_context *out,
477
+ PCRE2_UCHAR separator, BOOL with_escape)
478
+ {
479
+ out->out_str[0] = CHAR_LEFT_SQUARE_BRACKET;
480
+ out->out_str[1] = CHAR_CIRCUMFLEX_ACCENT;
481
+ convert_glob_write_str(out, 2);
482
+
483
+ convert_glob_print_separator(out, separator, with_escape);
484
+
485
+ convert_glob_write(out, CHAR_RIGHT_SQUARE_BRACKET);
486
+ }
487
+
488
+
489
+ /* Parse a posix class.
490
+
491
+ Arguments:
492
+ from starting point of scanning the range
493
+ pattern_end end of pattern
494
+ out output context
495
+
496
+ Returns: >0 => class index
497
+ 0 => malformed class
498
+ */
499
+
500
+ static int
501
+ convert_glob_parse_class(PCRE2_SPTR *from, PCRE2_SPTR pattern_end,
502
+ pcre2_output_context *out)
503
+ {
504
+ PCRE2_SPTR start = *from + 1;
505
+ PCRE2_SPTR pattern = start;
506
+ const char *class_ptr;
507
+ PCRE2_UCHAR c;
508
+ int class_index;
509
+
510
+ while (TRUE)
511
+ {
512
+ if (pattern >= pattern_end) return 0;
513
+
514
+ c = *pattern++;
515
+
516
+ if (c < CHAR_a || c > CHAR_z) break;
517
+ }
518
+
519
+ if (c != CHAR_COLON || pattern >= pattern_end ||
520
+ *pattern != CHAR_RIGHT_SQUARE_BRACKET)
521
+ return 0;
522
+
523
+ class_ptr = posix_classes;
524
+ class_index = 1;
525
+
526
+ while (TRUE)
527
+ {
528
+ if (*class_ptr == 0) return 0;
529
+
530
+ pattern = start;
531
+
532
+ while (*pattern == (PCRE2_UCHAR) *class_ptr)
533
+ {
534
+ if (*pattern == CHAR_COLON)
535
+ {
536
+ pattern += 2;
537
+ start -= 2;
538
+
539
+ do convert_glob_write(out, *start++); while (start < pattern);
540
+
541
+ *from = pattern;
542
+ return class_index;
543
+ }
544
+ pattern++;
545
+ class_ptr++;
546
+ }
547
+
548
+ while (*class_ptr != CHAR_COLON) class_ptr++;
549
+ class_ptr++;
550
+ class_index++;
551
+ }
552
+ }
553
+
554
+ /* Checks whether the character is in the class.
555
+
556
+ Arguments:
557
+ class_index class index
558
+ c character
559
+
560
+ Returns: !0 => character is found in the class
561
+ 0 => otherwise
562
+ */
563
+
564
+ static BOOL
565
+ convert_glob_char_in_class(int class_index, PCRE2_UCHAR c)
566
+ {
567
+ const uint8_t *cbits = PRIV(default_tables) + cbits_offset;
568
+ int cbit;
569
+
570
+ #if PCRE2_CODE_UNIT_WIDTH != 8
571
+ if (c > 0xff)
572
+ {
573
+ /* Can't access the character tables for c > 0xff */
574
+ return FALSE;
575
+ }
576
+ #endif
577
+
578
+ /* See posix_class_maps. This is a small local clone of that.
579
+ Note that we don't know exactly what character tables will be used at
580
+ match time, but, for the purposes of pattern conversion, it should be
581
+ sufficient to use PCRE2's built-in default tables. */
582
+
583
+ switch (class_index)
584
+ {
585
+ case 1: /* alpha */
586
+ if (c == CHAR_UNDERSCORE) return FALSE;
587
+ if (((cbits + cbit_digit)[c/8] & (1u << (c&7))) != 0) return FALSE;
588
+ cbit = cbit_word;
589
+ break;
590
+
591
+ case 2: cbit = cbit_lower; break; /* lower */
592
+ case 3: cbit = cbit_upper; break; /* upper */
593
+
594
+ case 4: /* alnum */
595
+ if (c == CHAR_UNDERSCORE) return FALSE;
596
+ cbit = cbit_word;
597
+ break;
598
+
599
+ case 5: /* ascii */
600
+ if (((cbits + cbit_cntrl)[c/8] & (1u << (c&7))) != 0) return TRUE;
601
+ cbit = cbit_print;
602
+ break;
603
+
604
+ case 6: /* blank */
605
+ if (c == CHAR_LF || c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
606
+ return FALSE;
607
+ cbit = cbit_space;
608
+ break;
609
+
610
+ case 7: cbit = cbit_cntrl; break; /* cntrl */
611
+ case 8: cbit = cbit_digit; break; /* digit */
612
+ case 9: cbit = cbit_graph; break; /* graph */
613
+ case 10: cbit = cbit_print; break; /* print */
614
+ case 11: cbit = cbit_punct; break; /* punct */
615
+ case 12: cbit = cbit_space; break; /* space */
616
+ case 13: cbit = cbit_word; break; /* word */
617
+ case 14: cbit = cbit_xdigit; break; /* xdigit */
618
+ default: return FALSE;
619
+ }
620
+
621
+ return ((cbits + cbit)[c/8] & (1u << (c&7))) != 0;
622
+ }
623
+
624
+ /* Parse a range of characters.
625
+
626
+ Arguments:
627
+ from starting point of scanning the range
628
+ pattern_end end of pattern
629
+ out output context
630
+ separator glob separator
631
+ with_escape backslash is needed before separator
632
+
633
+ Returns: 0 => success
634
+ !0 => error code
635
+ */
636
+
637
+ static int
638
+ convert_glob_parse_range(PCRE2_SPTR *from, PCRE2_SPTR pattern_end,
639
+ pcre2_output_context *out, BOOL utf, PCRE2_UCHAR separator,
640
+ BOOL with_escape, PCRE2_UCHAR escape, BOOL no_wildsep)
641
+ {
642
+ BOOL is_negative = FALSE;
643
+ BOOL separator_seen = FALSE;
644
+ BOOL has_prev_c;
645
+ PCRE2_SPTR pattern = *from;
646
+ PCRE2_SPTR char_start = NULL;
647
+ uint32_t c, prev_c;
648
+ int len, class_index;
649
+
650
+ (void)utf; /* Avoid compiler warning. */
651
+
652
+ if (pattern >= pattern_end)
653
+ {
654
+ *from = pattern;
655
+ return PCRE2_ERROR_MISSING_SQUARE_BRACKET;
656
+ }
657
+
658
+ if (*pattern == CHAR_EXCLAMATION_MARK
659
+ || *pattern == CHAR_CIRCUMFLEX_ACCENT)
660
+ {
661
+ pattern++;
662
+
663
+ if (pattern >= pattern_end)
664
+ {
665
+ *from = pattern;
666
+ return PCRE2_ERROR_MISSING_SQUARE_BRACKET;
667
+ }
668
+
669
+ is_negative = TRUE;
670
+
671
+ out->out_str[0] = CHAR_LEFT_SQUARE_BRACKET;
672
+ out->out_str[1] = CHAR_CIRCUMFLEX_ACCENT;
673
+ len = 2;
674
+
675
+ if (!no_wildsep)
676
+ {
677
+ if (with_escape)
678
+ {
679
+ out->out_str[len] = CHAR_BACKSLASH;
680
+ len++;
681
+ }
682
+ out->out_str[len] = (uint8_t) separator;
683
+ }
684
+
685
+ convert_glob_write_str(out, len + 1);
686
+ }
687
+ else
688
+ convert_glob_write(out, CHAR_LEFT_SQUARE_BRACKET);
689
+
690
+ has_prev_c = FALSE;
691
+ prev_c = 0;
692
+
693
+ if (*pattern == CHAR_RIGHT_SQUARE_BRACKET)
694
+ {
695
+ out->out_str[0] = CHAR_BACKSLASH;
696
+ out->out_str[1] = CHAR_RIGHT_SQUARE_BRACKET;
697
+ convert_glob_write_str(out, 2);
698
+ has_prev_c = TRUE;
699
+ prev_c = CHAR_RIGHT_SQUARE_BRACKET;
700
+ pattern++;
701
+ }
702
+
703
+ while (pattern < pattern_end)
704
+ {
705
+ char_start = pattern;
706
+ GETCHARINCTEST(c, pattern);
707
+
708
+ if (c == CHAR_RIGHT_SQUARE_BRACKET)
709
+ {
710
+ convert_glob_write(out, c);
711
+
712
+ if (!is_negative && !no_wildsep && separator_seen)
713
+ {
714
+ out->out_str[0] = CHAR_LEFT_PARENTHESIS;
715
+ out->out_str[1] = CHAR_QUESTION_MARK;
716
+ out->out_str[2] = CHAR_LESS_THAN_SIGN;
717
+ out->out_str[3] = CHAR_EXCLAMATION_MARK;
718
+ convert_glob_write_str(out, 4);
719
+
720
+ convert_glob_print_separator(out, separator, with_escape);
721
+ convert_glob_write(out, CHAR_RIGHT_PARENTHESIS);
722
+ }
723
+
724
+ *from = pattern;
725
+ return 0;
726
+ }
727
+
728
+ if (pattern >= pattern_end) break;
729
+
730
+ if (c == CHAR_LEFT_SQUARE_BRACKET && *pattern == CHAR_COLON)
731
+ {
732
+ *from = pattern;
733
+ class_index = convert_glob_parse_class(from, pattern_end, out);
734
+
735
+ if (class_index != 0)
736
+ {
737
+ pattern = *from;
738
+
739
+ has_prev_c = FALSE;
740
+ prev_c = 0;
741
+
742
+ if (!is_negative &&
743
+ convert_glob_char_in_class (class_index, separator))
744
+ separator_seen = TRUE;
745
+ continue;
746
+ }
747
+ }
748
+ else if (c == CHAR_MINUS && has_prev_c &&
749
+ *pattern != CHAR_RIGHT_SQUARE_BRACKET)
750
+ {
751
+ convert_glob_write(out, CHAR_MINUS);
752
+
753
+ char_start = pattern;
754
+ GETCHARINCTEST(c, pattern);
755
+
756
+ if (pattern >= pattern_end) break;
757
+
758
+ if (escape != 0 && c == escape)
759
+ {
760
+ char_start = pattern;
761
+ GETCHARINCTEST(c, pattern);
762
+ }
763
+ else if (c == CHAR_LEFT_SQUARE_BRACKET && *pattern == CHAR_COLON)
764
+ {
765
+ *from = pattern;
766
+ return PCRE2_ERROR_CONVERT_SYNTAX;
767
+ }
768
+
769
+ if (prev_c > c)
770
+ {
771
+ *from = pattern;
772
+ return PCRE2_ERROR_CONVERT_SYNTAX;
773
+ }
774
+
775
+ if (prev_c < separator && separator < c) separator_seen = TRUE;
776
+
777
+ has_prev_c = FALSE;
778
+ prev_c = 0;
779
+ }
780
+ else
781
+ {
782
+ if (escape != 0 && c == escape)
783
+ {
784
+ char_start = pattern;
785
+ GETCHARINCTEST(c, pattern);
786
+
787
+ if (pattern >= pattern_end) break;
788
+ }
789
+
790
+ has_prev_c = TRUE;
791
+ prev_c = c;
792
+ }
793
+
794
+ if (c == CHAR_LEFT_SQUARE_BRACKET || c == CHAR_RIGHT_SQUARE_BRACKET ||
795
+ c == CHAR_BACKSLASH || c == CHAR_MINUS)
796
+ convert_glob_write(out, CHAR_BACKSLASH);
797
+
798
+ if (c == separator) separator_seen = TRUE;
799
+
800
+ do convert_glob_write(out, *char_start++); while (char_start < pattern);
801
+ }
802
+
803
+ *from = pattern;
804
+ return PCRE2_ERROR_MISSING_SQUARE_BRACKET;
805
+ }
806
+
807
+
808
+ /* Prints a (*COMMIT) into the output.
809
+
810
+ Arguments:
811
+ out output context
812
+ */
813
+
814
+ static void
815
+ convert_glob_print_commit(pcre2_output_context *out)
816
+ {
817
+ out->out_str[0] = CHAR_LEFT_PARENTHESIS;
818
+ out->out_str[1] = CHAR_ASTERISK;
819
+ out->out_str[2] = CHAR_C;
820
+ out->out_str[3] = CHAR_O;
821
+ out->out_str[4] = CHAR_M;
822
+ out->out_str[5] = CHAR_M;
823
+ out->out_str[6] = CHAR_I;
824
+ out->out_str[7] = CHAR_T;
825
+ convert_glob_write_str(out, 8);
826
+ convert_glob_write(out, CHAR_RIGHT_PARENTHESIS);
827
+ }
828
+
829
+
830
+ /* Bash glob converter.
831
+
832
+ Arguments:
833
+ pattype the pattern type
834
+ pattern the pattern
835
+ plength length in code units
836
+ utf TRUE if UTF
837
+ use_buffer where to put the output
838
+ use_length length of use_buffer
839
+ bufflenptr where to put the used length
840
+ dummyrun TRUE if a dummy run
841
+ ccontext the convert context
842
+
843
+ Returns: 0 => success
844
+ !0 => error code
845
+ */
846
+
847
+ static int
848
+ convert_glob(uint32_t options, PCRE2_SPTR pattern, PCRE2_SIZE plength,
849
+ BOOL utf, PCRE2_UCHAR *use_buffer, PCRE2_SIZE use_length,
850
+ PCRE2_SIZE *bufflenptr, BOOL dummyrun, pcre2_convert_context *ccontext)
851
+ {
852
+ pcre2_output_context out;
853
+ PCRE2_SPTR pattern_start = pattern;
854
+ PCRE2_SPTR pattern_end = pattern + plength;
855
+ PCRE2_UCHAR separator = ccontext->glob_separator;
856
+ PCRE2_UCHAR escape = ccontext->glob_escape;
857
+ PCRE2_UCHAR c;
858
+ BOOL no_wildsep = (options & PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR) != 0;
859
+ BOOL no_starstar = (options & PCRE2_CONVERT_GLOB_NO_STARSTAR) != 0;
860
+ BOOL in_atomic = FALSE;
861
+ BOOL after_starstar = FALSE;
862
+ BOOL no_slash_z = FALSE;
863
+ BOOL with_escape, is_start, after_separator;
864
+ int result = 0;
865
+
866
+ (void)utf; /* Avoid compiler warning. */
867
+
868
+ #ifdef SUPPORT_UNICODE
869
+ if (utf && (separator >= 128 || escape >= 128))
870
+ {
871
+ /* Currently only ASCII characters are supported. */
872
+ *bufflenptr = 0;
873
+ return PCRE2_ERROR_CONVERT_SYNTAX;
874
+ }
875
+ #endif
876
+
877
+ with_escape = strchr(pcre2_escaped_literals, separator) != NULL;
878
+
879
+ /* Initialize default for error offset as end of input. */
880
+ out.output = use_buffer;
881
+ out.output_end = use_buffer + use_length;
882
+ out.output_size = 0;
883
+
884
+ out.out_str[0] = CHAR_LEFT_PARENTHESIS;
885
+ out.out_str[1] = CHAR_QUESTION_MARK;
886
+ out.out_str[2] = CHAR_s;
887
+ out.out_str[3] = CHAR_RIGHT_PARENTHESIS;
888
+ convert_glob_write_str(&out, 4);
889
+
890
+ is_start = TRUE;
891
+
892
+ if (pattern < pattern_end && pattern[0] == CHAR_ASTERISK)
893
+ {
894
+ if (no_wildsep)
895
+ is_start = FALSE;
896
+ else if (!no_starstar && pattern + 1 < pattern_end &&
897
+ pattern[1] == CHAR_ASTERISK)
898
+ is_start = FALSE;
899
+ }
900
+
901
+ if (is_start)
902
+ {
903
+ out.out_str[0] = CHAR_BACKSLASH;
904
+ out.out_str[1] = CHAR_A;
905
+ convert_glob_write_str(&out, 2);
906
+ }
907
+
908
+ while (pattern < pattern_end)
909
+ {
910
+ c = *pattern++;
911
+
912
+ if (c == CHAR_ASTERISK)
913
+ {
914
+ is_start = pattern == pattern_start + 1;
915
+
916
+ if (in_atomic)
917
+ {
918
+ convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS);
919
+ in_atomic = FALSE;
920
+ }
921
+
922
+ if (!no_starstar && pattern < pattern_end && *pattern == CHAR_ASTERISK)
923
+ {
924
+ after_separator = is_start || (pattern[-2] == separator);
925
+
926
+ do pattern++; while (pattern < pattern_end &&
927
+ *pattern == CHAR_ASTERISK);
928
+
929
+ if (pattern >= pattern_end)
930
+ {
931
+ no_slash_z = TRUE;
932
+ break;
933
+ }
934
+
935
+ after_starstar = TRUE;
936
+
937
+ if (after_separator && escape != 0 && *pattern == escape &&
938
+ pattern + 1 < pattern_end && pattern[1] == separator)
939
+ pattern++;
940
+
941
+ if (is_start)
942
+ {
943
+ if (*pattern != separator) continue;
944
+
945
+ out.out_str[0] = CHAR_LEFT_PARENTHESIS;
946
+ out.out_str[1] = CHAR_QUESTION_MARK;
947
+ out.out_str[2] = CHAR_COLON;
948
+ out.out_str[3] = CHAR_BACKSLASH;
949
+ out.out_str[4] = CHAR_A;
950
+ out.out_str[5] = CHAR_VERTICAL_LINE;
951
+ convert_glob_write_str(&out, 6);
952
+
953
+ convert_glob_print_separator(&out, separator, with_escape);
954
+ convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS);
955
+
956
+ pattern++;
957
+ continue;
958
+ }
959
+
960
+ convert_glob_print_commit(&out);
961
+
962
+ if (!after_separator || *pattern != separator)
963
+ {
964
+ out.out_str[0] = CHAR_DOT;
965
+ out.out_str[1] = CHAR_ASTERISK;
966
+ out.out_str[2] = CHAR_QUESTION_MARK;
967
+ convert_glob_write_str(&out, 3);
968
+ continue;
969
+ }
970
+
971
+ out.out_str[0] = CHAR_LEFT_PARENTHESIS;
972
+ out.out_str[1] = CHAR_QUESTION_MARK;
973
+ out.out_str[2] = CHAR_COLON;
974
+ out.out_str[3] = CHAR_DOT;
975
+ out.out_str[4] = CHAR_ASTERISK;
976
+ out.out_str[5] = CHAR_QUESTION_MARK;
977
+
978
+ convert_glob_write_str(&out, 6);
979
+
980
+ convert_glob_print_separator(&out, separator, with_escape);
981
+
982
+ out.out_str[0] = CHAR_RIGHT_PARENTHESIS;
983
+ out.out_str[1] = CHAR_QUESTION_MARK;
984
+ out.out_str[2] = CHAR_QUESTION_MARK;
985
+ convert_glob_write_str(&out, 3);
986
+
987
+ pattern++;
988
+ continue;
989
+ }
990
+
991
+ if (pattern < pattern_end && *pattern == CHAR_ASTERISK)
992
+ {
993
+ do pattern++; while (pattern < pattern_end &&
994
+ *pattern == CHAR_ASTERISK);
995
+ }
996
+
997
+ if (no_wildsep)
998
+ {
999
+ if (pattern >= pattern_end)
1000
+ {
1001
+ no_slash_z = TRUE;
1002
+ break;
1003
+ }
1004
+
1005
+ /* Start check must be after the end check. */
1006
+ if (is_start) continue;
1007
+ }
1008
+
1009
+ if (!is_start)
1010
+ {
1011
+ if (after_starstar)
1012
+ {
1013
+ out.out_str[0] = CHAR_LEFT_PARENTHESIS;
1014
+ out.out_str[1] = CHAR_QUESTION_MARK;
1015
+ out.out_str[2] = CHAR_GREATER_THAN_SIGN;
1016
+ convert_glob_write_str(&out, 3);
1017
+ in_atomic = TRUE;
1018
+ }
1019
+ else
1020
+ convert_glob_print_commit(&out);
1021
+ }
1022
+
1023
+ if (no_wildsep)
1024
+ convert_glob_write(&out, CHAR_DOT);
1025
+ else
1026
+ convert_glob_print_wildcard(&out, separator, with_escape);
1027
+
1028
+ out.out_str[0] = CHAR_ASTERISK;
1029
+ out.out_str[1] = CHAR_QUESTION_MARK;
1030
+ if (pattern >= pattern_end)
1031
+ out.out_str[1] = CHAR_PLUS;
1032
+ convert_glob_write_str(&out, 2);
1033
+ continue;
1034
+ }
1035
+
1036
+ if (c == CHAR_QUESTION_MARK)
1037
+ {
1038
+ if (no_wildsep)
1039
+ convert_glob_write(&out, CHAR_DOT);
1040
+ else
1041
+ convert_glob_print_wildcard(&out, separator, with_escape);
1042
+ continue;
1043
+ }
1044
+
1045
+ if (c == CHAR_LEFT_SQUARE_BRACKET)
1046
+ {
1047
+ result = convert_glob_parse_range(&pattern, pattern_end,
1048
+ &out, utf, separator, with_escape, escape, no_wildsep);
1049
+ if (result != 0) break;
1050
+ continue;
1051
+ }
1052
+
1053
+ if (escape != 0 && c == escape)
1054
+ {
1055
+ if (pattern >= pattern_end)
1056
+ {
1057
+ result = PCRE2_ERROR_CONVERT_SYNTAX;
1058
+ break;
1059
+ }
1060
+ c = *pattern++;
1061
+ }
1062
+
1063
+ if (c < 255 && strchr(pcre2_escaped_literals, c) != NULL)
1064
+ convert_glob_write(&out, CHAR_BACKSLASH);
1065
+
1066
+ convert_glob_write(&out, c);
1067
+ }
1068
+
1069
+ if (result == 0)
1070
+ {
1071
+ if (!no_slash_z)
1072
+ {
1073
+ out.out_str[0] = CHAR_BACKSLASH;
1074
+ out.out_str[1] = CHAR_z;
1075
+ convert_glob_write_str(&out, 2);
1076
+ }
1077
+
1078
+ if (in_atomic)
1079
+ convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS);
1080
+
1081
+ convert_glob_write(&out, CHAR_NUL);
1082
+
1083
+ if (!dummyrun && out.output_size != (PCRE2_SIZE) (out.output - use_buffer))
1084
+ result = PCRE2_ERROR_NOMEMORY;
1085
+ }
1086
+
1087
+ if (result != 0)
1088
+ {
1089
+ *bufflenptr = pattern - pattern_start;
1090
+ return result;
1091
+ }
1092
+
1093
+ *bufflenptr = out.output_size - 1;
1094
+ return 0;
1095
+ }
1096
+
1097
+
1098
+ /*************************************************
1099
+ * Convert pattern *
1100
+ *************************************************/
1101
+
1102
+ /* This is the external-facing function for converting other forms of pattern
1103
+ into PCRE2 regular expression patterns. On error, the bufflenptr argument is
1104
+ used to return an offset in the original pattern.
1105
+
1106
+ Arguments:
1107
+ pattern the input pattern
1108
+ plength length of input, or PCRE2_ZERO_TERMINATED
1109
+ options options bits
1110
+ buffptr pointer to pointer to output buffer
1111
+ bufflenptr pointer to length of output buffer
1112
+ ccontext convert context or NULL
1113
+
1114
+ Returns: 0 for success, else an error code (+ve or -ve)
1115
+ */
1116
+
1117
+ PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
1118
+ pcre2_pattern_convert(PCRE2_SPTR pattern, PCRE2_SIZE plength, uint32_t options,
1119
+ PCRE2_UCHAR **buffptr, PCRE2_SIZE *bufflenptr,
1120
+ pcre2_convert_context *ccontext)
1121
+ {
1122
+ int rc;
1123
+ PCRE2_UCHAR null_str[1] = { 0xcd };
1124
+ PCRE2_UCHAR dummy_buffer[DUMMY_BUFFER_SIZE];
1125
+ PCRE2_UCHAR *use_buffer = dummy_buffer;
1126
+ PCRE2_SIZE use_length = DUMMY_BUFFER_SIZE;
1127
+ BOOL utf = (options & PCRE2_CONVERT_UTF) != 0;
1128
+ uint32_t pattype = options & TYPE_OPTIONS;
1129
+ int i;
1130
+
1131
+ if (pattern == NULL && plength == 0)
1132
+ pattern = null_str;
1133
+
1134
+ if (pattern == NULL || bufflenptr == NULL)
1135
+ {
1136
+ if (bufflenptr != NULL) *bufflenptr = 0; /* Error offset */
1137
+ return PCRE2_ERROR_NULL;
1138
+ }
1139
+
1140
+ if ((options & ~ALL_OPTIONS) != 0 || /* Undefined bit set */
1141
+ (pattype & (~pattype+1)) != pattype || /* More than one type set */
1142
+ pattype == 0) /* No type set */
1143
+ {
1144
+ *bufflenptr = 0; /* Error offset */
1145
+ return PCRE2_ERROR_BADOPTION;
1146
+ }
1147
+
1148
+ if (plength == PCRE2_ZERO_TERMINATED) plength = PRIV(strlen)(pattern);
1149
+ if (ccontext == NULL) ccontext =
1150
+ (pcre2_convert_context *)(&PRIV(default_convert_context));
1151
+
1152
+ /* Check UTF if required. */
1153
+
1154
+ #ifndef SUPPORT_UNICODE
1155
+ if (utf)
1156
+ {
1157
+ *bufflenptr = 0; /* Error offset */
1158
+ return PCRE2_ERROR_UNICODE_NOT_SUPPORTED;
1159
+ }
1160
+ #else
1161
+ if (utf && (options & PCRE2_CONVERT_NO_UTF_CHECK) == 0)
1162
+ {
1163
+ PCRE2_SIZE erroroffset;
1164
+ rc = PRIV(valid_utf)(pattern, plength, &erroroffset);
1165
+ if (rc != 0)
1166
+ {
1167
+ *bufflenptr = erroroffset;
1168
+ return rc;
1169
+ }
1170
+ }
1171
+ #endif
1172
+
1173
+ /* If buffptr is not NULL, and what it points to is not NULL, we are being
1174
+ provided with a buffer and a length, so set them as the buffer to use. */
1175
+
1176
+ if (buffptr != NULL && *buffptr != NULL)
1177
+ {
1178
+ use_buffer = *buffptr;
1179
+ use_length = *bufflenptr;
1180
+ }
1181
+
1182
+ /* Call an individual converter, either just once (if a buffer was provided or
1183
+ just the length is needed), or twice (if a memory allocation is required). */
1184
+
1185
+ for (i = 0; i < 2; i++)
1186
+ {
1187
+ PCRE2_UCHAR *allocated;
1188
+ BOOL dummyrun = buffptr == NULL || *buffptr == NULL;
1189
+
1190
+ switch(pattype)
1191
+ {
1192
+ case PCRE2_CONVERT_GLOB:
1193
+ rc = convert_glob(options & ~PCRE2_CONVERT_GLOB, pattern, plength, utf,
1194
+ use_buffer, use_length, bufflenptr, dummyrun, ccontext);
1195
+ break;
1196
+
1197
+ case PCRE2_CONVERT_POSIX_BASIC:
1198
+ case PCRE2_CONVERT_POSIX_EXTENDED:
1199
+ rc = convert_posix(pattype, pattern, plength, utf, use_buffer, use_length,
1200
+ bufflenptr, dummyrun, ccontext);
1201
+ break;
1202
+
1203
+ /* We have already validated pattype. */
1204
+ /* LCOV_EXCL_START */
1205
+ default:
1206
+ PCRE2_DEBUG_UNREACHABLE();
1207
+ *bufflenptr = 0; /* Error offset */
1208
+ return PCRE2_ERROR_INTERNAL;
1209
+ /* LCOV_EXCL_STOP */
1210
+ }
1211
+
1212
+ if (rc != 0 || /* Error */
1213
+ buffptr == NULL || /* Just the length is required */
1214
+ *buffptr != NULL) /* Buffer was provided or allocated */
1215
+ return rc;
1216
+
1217
+ /* Allocate memory for the buffer, with hidden space for an allocator at
1218
+ the start. The next time round the loop runs the conversion for real. */
1219
+
1220
+ allocated = PRIV(memctl_malloc)(sizeof(pcre2_memctl) +
1221
+ (*bufflenptr + 1)*PCRE2_CODE_UNIT_WIDTH, (pcre2_memctl *)ccontext);
1222
+ if (allocated == NULL)
1223
+ {
1224
+ *bufflenptr = 0; /* Error offset */
1225
+ return PCRE2_ERROR_NOMEMORY;
1226
+ }
1227
+ *buffptr = (PCRE2_UCHAR *)(((char *)allocated) + sizeof(pcre2_memctl));
1228
+
1229
+ use_buffer = *buffptr;
1230
+ use_length = *bufflenptr + 1;
1231
+ }
1232
+
1233
+ /* Running the loop above ought to have succeeded the second time. */
1234
+ /* LCOV_EXCL_START */
1235
+ PCRE2_DEBUG_UNREACHABLE();
1236
+ *bufflenptr = 0; /* Error offset */
1237
+ return PCRE2_ERROR_INTERNAL;
1238
+ /* LCOV_EXCL_STOP */
1239
+ }
1240
+
1241
+
1242
+ /*************************************************
1243
+ * Free converted pattern *
1244
+ *************************************************/
1245
+
1246
+ /* This frees a converted pattern that was put in newly-allocated memory.
1247
+
1248
+ Argument: the converted pattern
1249
+ Returns: nothing
1250
+ */
1251
+
1252
+ PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
1253
+ pcre2_converted_pattern_free(PCRE2_UCHAR *converted)
1254
+ {
1255
+ if (converted != NULL)
1256
+ {
1257
+ pcre2_memctl *memctl =
1258
+ (pcre2_memctl *)((char *)converted - sizeof(pcre2_memctl));
1259
+ memctl->free(memctl, memctl->memory_data);
1260
+ }
1261
+ }
1262
+
1263
+ /* End of pcre2_convert.c */