| 6 |
and semantics are as close as possible to those of the Perl 5 language. |
and semantics are as close as possible to those of the Perl 5 language. |
| 7 |
|
|
| 8 |
Written by Philip Hazel |
Written by Philip Hazel |
| 9 |
Copyright (c) 1997-2009 University of Cambridge |
Copyright (c) 1997-2011 University of Cambridge |
| 10 |
|
|
| 11 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
| 12 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
| 53 |
#include "pcre_internal.h" |
#include "pcre_internal.h" |
| 54 |
|
|
| 55 |
|
|
| 56 |
/* When DEBUG is defined, we need the pcre_printint() function, which is also |
/* When PCRE_DEBUG is defined, we need the pcre_printint() function, which is |
| 57 |
used by pcretest. DEBUG is not defined when building a production library. */ |
also used by pcretest. PCRE_DEBUG is not defined when building a production |
| 58 |
|
library. */ |
| 59 |
|
|
| 60 |
#ifdef DEBUG |
#ifdef PCRE_DEBUG |
| 61 |
#include "pcre_printint.src" |
#include "pcre_printint.src" |
| 62 |
#endif |
#endif |
| 63 |
|
|
| 92 |
|
|
| 93 |
#define COMPILE_WORK_SIZE (4096) |
#define COMPILE_WORK_SIZE (4096) |
| 94 |
|
|
| 95 |
|
/* The overrun tests check for a slightly smaller size so that they detect the |
| 96 |
|
overrun before it actually does run off the end of the data block. */ |
| 97 |
|
|
| 98 |
|
#define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100) |
| 99 |
|
|
| 100 |
|
|
| 101 |
/* Table for handling escaped characters in the range '0'-'z'. Positive returns |
/* Table for handling escaped characters in the range '0'-'z'. Positive returns |
| 102 |
are simple data values; negative values are for special things like \d and so |
are simple data values; negative values are for special things like \d and so |
| 124 |
-ESC_H, 0, |
-ESC_H, 0, |
| 125 |
0, -ESC_K, |
0, -ESC_K, |
| 126 |
0, 0, |
0, 0, |
| 127 |
0, 0, |
-ESC_N, 0, |
| 128 |
-ESC_P, -ESC_Q, |
-ESC_P, -ESC_Q, |
| 129 |
-ESC_R, -ESC_S, |
-ESC_R, -ESC_S, |
| 130 |
0, 0, |
0, 0, |
| 171 |
/* B8 */ 0, 0, 0, 0, 0, ']', '=', '-', |
/* B8 */ 0, 0, 0, 0, 0, ']', '=', '-', |
| 172 |
/* C0 */ '{',-ESC_A, -ESC_B, -ESC_C, -ESC_D,-ESC_E, 0, -ESC_G, |
/* C0 */ '{',-ESC_A, -ESC_B, -ESC_C, -ESC_D,-ESC_E, 0, -ESC_G, |
| 173 |
/* C8 */-ESC_H, 0, 0, 0, 0, 0, 0, 0, |
/* C8 */-ESC_H, 0, 0, 0, 0, 0, 0, 0, |
| 174 |
/* D0 */ '}', 0, -ESC_K, 0, 0, 0, 0, -ESC_P, |
/* D0 */ '}', 0, -ESC_K, 0, 0,-ESC_N, 0, -ESC_P, |
| 175 |
/* D8 */-ESC_Q,-ESC_R, 0, 0, 0, 0, 0, 0, |
/* D8 */-ESC_Q,-ESC_R, 0, 0, 0, 0, 0, 0, |
| 176 |
/* E0 */ '\\', 0, -ESC_S, 0, 0,-ESC_V, -ESC_W, -ESC_X, |
/* E0 */ '\\', 0, -ESC_S, 0, 0,-ESC_V, -ESC_W, -ESC_X, |
| 177 |
/* E8 */ 0,-ESC_Z, 0, 0, 0, 0, 0, 0, |
/* E8 */ 0,-ESC_Z, 0, 0, 0, 0, 0, 0, |
| 188 |
platforms. */ |
platforms. */ |
| 189 |
|
|
| 190 |
typedef struct verbitem { |
typedef struct verbitem { |
| 191 |
int len; |
int len; /* Length of verb name */ |
| 192 |
int op; |
int op; /* Op when no arg, or -1 if arg mandatory */ |
| 193 |
|
int op_arg; /* Op when arg present, or -1 if not allowed */ |
| 194 |
} verbitem; |
} verbitem; |
| 195 |
|
|
| 196 |
static const char verbnames[] = |
static const char verbnames[] = |
| 197 |
|
"\0" /* Empty name is a shorthand for MARK */ |
| 198 |
|
STRING_MARK0 |
| 199 |
STRING_ACCEPT0 |
STRING_ACCEPT0 |
| 200 |
STRING_COMMIT0 |
STRING_COMMIT0 |
| 201 |
STRING_F0 |
STRING_F0 |
| 205 |
STRING_THEN; |
STRING_THEN; |
| 206 |
|
|
| 207 |
static const verbitem verbs[] = { |
static const verbitem verbs[] = { |
| 208 |
{ 6, OP_ACCEPT }, |
{ 0, -1, OP_MARK }, |
| 209 |
{ 6, OP_COMMIT }, |
{ 4, -1, OP_MARK }, |
| 210 |
{ 1, OP_FAIL }, |
{ 6, OP_ACCEPT, -1 }, |
| 211 |
{ 4, OP_FAIL }, |
{ 6, OP_COMMIT, -1 }, |
| 212 |
{ 5, OP_PRUNE }, |
{ 1, OP_FAIL, -1 }, |
| 213 |
{ 4, OP_SKIP }, |
{ 4, OP_FAIL, -1 }, |
| 214 |
{ 4, OP_THEN } |
{ 5, OP_PRUNE, OP_PRUNE_ARG }, |
| 215 |
|
{ 4, OP_SKIP, OP_SKIP_ARG }, |
| 216 |
|
{ 4, OP_THEN, OP_THEN_ARG } |
| 217 |
}; |
}; |
| 218 |
|
|
| 219 |
static const int verbcount = sizeof(verbs)/sizeof(verbitem); |
static const int verbcount = sizeof(verbs)/sizeof(verbitem); |
| 261 |
cbit_xdigit,-1, 0 /* xdigit */ |
cbit_xdigit,-1, 0 /* xdigit */ |
| 262 |
}; |
}; |
| 263 |
|
|
| 264 |
|
/* Table of substitutes for \d etc when PCRE_UCP is set. The POSIX class |
| 265 |
|
substitutes must be in the order of the names, defined above, and there are |
| 266 |
|
both positive and negative cases. NULL means no substitute. */ |
| 267 |
|
|
| 268 |
|
#ifdef SUPPORT_UCP |
| 269 |
|
static const uschar *substitutes[] = { |
| 270 |
|
(uschar *)"\\P{Nd}", /* \D */ |
| 271 |
|
(uschar *)"\\p{Nd}", /* \d */ |
| 272 |
|
(uschar *)"\\P{Xsp}", /* \S */ /* NOTE: Xsp is Perl space */ |
| 273 |
|
(uschar *)"\\p{Xsp}", /* \s */ |
| 274 |
|
(uschar *)"\\P{Xwd}", /* \W */ |
| 275 |
|
(uschar *)"\\p{Xwd}" /* \w */ |
| 276 |
|
}; |
| 277 |
|
|
| 278 |
|
static const uschar *posix_substitutes[] = { |
| 279 |
|
(uschar *)"\\p{L}", /* alpha */ |
| 280 |
|
(uschar *)"\\p{Ll}", /* lower */ |
| 281 |
|
(uschar *)"\\p{Lu}", /* upper */ |
| 282 |
|
(uschar *)"\\p{Xan}", /* alnum */ |
| 283 |
|
NULL, /* ascii */ |
| 284 |
|
(uschar *)"\\h", /* blank */ |
| 285 |
|
NULL, /* cntrl */ |
| 286 |
|
(uschar *)"\\p{Nd}", /* digit */ |
| 287 |
|
NULL, /* graph */ |
| 288 |
|
NULL, /* print */ |
| 289 |
|
NULL, /* punct */ |
| 290 |
|
(uschar *)"\\p{Xps}", /* space */ /* NOTE: Xps is POSIX space */ |
| 291 |
|
(uschar *)"\\p{Xwd}", /* word */ |
| 292 |
|
NULL, /* xdigit */ |
| 293 |
|
/* Negated cases */ |
| 294 |
|
(uschar *)"\\P{L}", /* ^alpha */ |
| 295 |
|
(uschar *)"\\P{Ll}", /* ^lower */ |
| 296 |
|
(uschar *)"\\P{Lu}", /* ^upper */ |
| 297 |
|
(uschar *)"\\P{Xan}", /* ^alnum */ |
| 298 |
|
NULL, /* ^ascii */ |
| 299 |
|
(uschar *)"\\H", /* ^blank */ |
| 300 |
|
NULL, /* ^cntrl */ |
| 301 |
|
(uschar *)"\\P{Nd}", /* ^digit */ |
| 302 |
|
NULL, /* ^graph */ |
| 303 |
|
NULL, /* ^print */ |
| 304 |
|
NULL, /* ^punct */ |
| 305 |
|
(uschar *)"\\P{Xps}", /* ^space */ /* NOTE: Xps is POSIX space */ |
| 306 |
|
(uschar *)"\\P{Xwd}", /* ^word */ |
| 307 |
|
NULL /* ^xdigit */ |
| 308 |
|
}; |
| 309 |
|
#define POSIX_SUBSIZE (sizeof(posix_substitutes)/sizeof(uschar *)) |
| 310 |
|
#endif |
| 311 |
|
|
| 312 |
#define STRING(a) # a |
#define STRING(a) # a |
| 313 |
#define XSTRING(s) STRING(s) |
#define XSTRING(s) STRING(s) |
| 320 |
it is now one long string. We cannot use a table of offsets, because the |
it is now one long string. We cannot use a table of offsets, because the |
| 321 |
lengths of inserts such as XSTRING(MAX_NAME_SIZE) are not known. Instead, we |
lengths of inserts such as XSTRING(MAX_NAME_SIZE) are not known. Instead, we |
| 322 |
simply count through to the one we want - this isn't a performance issue |
simply count through to the one we want - this isn't a performance issue |
| 323 |
because these strings are used only when there is a compilation error. */ |
because these strings are used only when there is a compilation error. |
| 324 |
|
|
| 325 |
|
Each substring ends with \0 to insert a null character. This includes the final |
| 326 |
|
substring, so that the whole string ends with \0\0, which can be detected when |
| 327 |
|
counting through. */ |
| 328 |
|
|
| 329 |
static const char error_texts[] = |
static const char error_texts[] = |
| 330 |
"no error\0" |
"no error\0" |
| 371 |
/* 35 */ |
/* 35 */ |
| 372 |
"invalid condition (?(0)\0" |
"invalid condition (?(0)\0" |
| 373 |
"\\C not allowed in lookbehind assertion\0" |
"\\C not allowed in lookbehind assertion\0" |
| 374 |
"PCRE does not support \\L, \\l, \\N, \\U, or \\u\0" |
"PCRE does not support \\L, \\l, \\N{name}, \\U, or \\u\0" |
| 375 |
"number after (?C is > 255\0" |
"number after (?C is > 255\0" |
| 376 |
"closing ) for (?C expected\0" |
"closing ) for (?C expected\0" |
| 377 |
/* 40 */ |
/* 40 */ |
| 397 |
"inconsistent NEWLINE options\0" |
"inconsistent NEWLINE options\0" |
| 398 |
"\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number\0" |
"\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number\0" |
| 399 |
"a numbered reference must not be zero\0" |
"a numbered reference must not be zero\0" |
| 400 |
"(*VERB) with an argument is not supported\0" |
"an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0" |
| 401 |
/* 60 */ |
/* 60 */ |
| 402 |
"(*VERB) not recognized\0" |
"(*VERB) not recognized\0" |
| 403 |
"number is too big\0" |
"number is too big\0" |
| 405 |
"digit expected after (?+\0" |
"digit expected after (?+\0" |
| 406 |
"] is an invalid data character in JavaScript compatibility mode\0" |
"] is an invalid data character in JavaScript compatibility mode\0" |
| 407 |
/* 65 */ |
/* 65 */ |
| 408 |
"different names for subpatterns of the same number are not allowed"; |
"different names for subpatterns of the same number are not allowed\0" |
| 409 |
|
"(*MARK) must have an argument\0" |
| 410 |
|
"this version of PCRE is not compiled with PCRE_UCP support\0" |
| 411 |
|
"\\c must be followed by an ASCII character\0" |
| 412 |
|
; |
| 413 |
|
|
| 414 |
/* Table to identify digits and hex digits. This is used when compiling |
/* Table to identify digits and hex digits. This is used when compiling |
| 415 |
patterns. Note that the tables in chartables are dependent on the locale, and |
patterns. Note that the tables in chartables are dependent on the locale, and |
| 545 |
/* Definition to allow mutual recursion */ |
/* Definition to allow mutual recursion */ |
| 546 |
|
|
| 547 |
static BOOL |
static BOOL |
| 548 |
compile_regex(int, int, uschar **, const uschar **, int *, BOOL, BOOL, int, |
compile_regex(int, uschar **, const uschar **, int *, BOOL, BOOL, int, int *, |
| 549 |
int *, int *, branch_chain *, compile_data *, int *); |
int *, branch_chain *, compile_data *, int *); |
| 550 |
|
|
| 551 |
|
|
| 552 |
|
|
| 567 |
find_error_text(int n) |
find_error_text(int n) |
| 568 |
{ |
{ |
| 569 |
const char *s = error_texts; |
const char *s = error_texts; |
| 570 |
for (; n > 0; n--) while (*s++ != 0) {}; |
for (; n > 0; n--) |
| 571 |
|
{ |
| 572 |
|
while (*s++ != 0) {}; |
| 573 |
|
if (*s == 0) return "Error text not found (please report)"; |
| 574 |
|
} |
| 575 |
return s; |
return s; |
| 576 |
} |
} |
| 577 |
|
|
| 642 |
|
|
| 643 |
case CHAR_l: |
case CHAR_l: |
| 644 |
case CHAR_L: |
case CHAR_L: |
|
case CHAR_N: |
|
| 645 |
case CHAR_u: |
case CHAR_u: |
| 646 |
case CHAR_U: |
case CHAR_U: |
| 647 |
*errorcodeptr = ERR37; |
*errorcodeptr = ERR37; |
| 842 |
break; |
break; |
| 843 |
|
|
| 844 |
/* For \c, a following letter is upper-cased; then the 0x40 bit is flipped. |
/* For \c, a following letter is upper-cased; then the 0x40 bit is flipped. |
| 845 |
This coding is ASCII-specific, but then the whole concept of \cx is |
An error is given if the byte following \c is not an ASCII character. This |
| 846 |
|
coding is ASCII-specific, but then the whole concept of \cx is |
| 847 |
ASCII-specific. (However, an EBCDIC equivalent has now been added.) */ |
ASCII-specific. (However, an EBCDIC equivalent has now been added.) */ |
| 848 |
|
|
| 849 |
case CHAR_c: |
case CHAR_c: |
| 853 |
*errorcodeptr = ERR2; |
*errorcodeptr = ERR2; |
| 854 |
break; |
break; |
| 855 |
} |
} |
| 856 |
|
#ifndef EBCDIC /* ASCII/UTF-8 coding */ |
| 857 |
#ifndef EBCDIC /* ASCII/UTF-8 coding */ |
if (c > 127) /* Excludes all non-ASCII in either mode */ |
| 858 |
|
{ |
| 859 |
|
*errorcodeptr = ERR68; |
| 860 |
|
break; |
| 861 |
|
} |
| 862 |
if (c >= CHAR_a && c <= CHAR_z) c -= 32; |
if (c >= CHAR_a && c <= CHAR_z) c -= 32; |
| 863 |
c ^= 0x40; |
c ^= 0x40; |
| 864 |
#else /* EBCDIC coding */ |
#else /* EBCDIC coding */ |
| 865 |
if (c >= CHAR_a && c <= CHAR_z) c += 64; |
if (c >= CHAR_a && c <= CHAR_z) c += 64; |
| 866 |
c ^= 0xC0; |
c ^= 0xC0; |
| 867 |
#endif |
#endif |
| 884 |
} |
} |
| 885 |
} |
} |
| 886 |
|
|
| 887 |
|
/* Perl supports \N{name} for character names, as well as plain \N for "not |
| 888 |
|
newline". PCRE does not support \N{name}. */ |
| 889 |
|
|
| 890 |
|
if (c == -ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET) |
| 891 |
|
*errorcodeptr = ERR37; |
| 892 |
|
|
| 893 |
|
/* If PCRE_UCP is set, we change the values for \d etc. */ |
| 894 |
|
|
| 895 |
|
if ((options & PCRE_UCP) != 0 && c <= -ESC_D && c >= -ESC_w) |
| 896 |
|
c -= (ESC_DU - ESC_D); |
| 897 |
|
|
| 898 |
|
/* Set the pointer to the final character before returning. */ |
| 899 |
|
|
| 900 |
*ptrptr = ptr; |
*ptrptr = ptr; |
| 901 |
return c; |
return c; |
| 902 |
} |
} |
| 1105 |
start at a parenthesis. It scans along a pattern's text looking for capturing |
start at a parenthesis. It scans along a pattern's text looking for capturing |
| 1106 |
subpatterns, and counting them. If it finds a named pattern that matches the |
subpatterns, and counting them. If it finds a named pattern that matches the |
| 1107 |
name it is given, it returns its number. Alternatively, if the name is NULL, it |
name it is given, it returns its number. Alternatively, if the name is NULL, it |
| 1108 |
returns when it reaches a given numbered subpattern. We know that if (?P< is |
returns when it reaches a given numbered subpattern. Recursion is used to keep |
| 1109 |
encountered, the name will be terminated by '>' because that is checked in the |
track of subpatterns that reset the capturing group numbers - the (?| feature. |
| 1110 |
first pass. Recursion is used to keep track of subpatterns that reset the |
|
| 1111 |
capturing group numbers - the (?| feature. |
This function was originally called only from the second pass, in which we know |
| 1112 |
|
that if (?< or (?' or (?P< is encountered, the name will be correctly |
| 1113 |
|
terminated because that is checked in the first pass. There is now one call to |
| 1114 |
|
this function in the first pass, to check for a recursive back reference by |
| 1115 |
|
name (so that we can make the whole group atomic). In this case, we need check |
| 1116 |
|
only up to the current position in the pattern, and that is still OK because |
| 1117 |
|
and previous occurrences will have been checked. To make this work, the test |
| 1118 |
|
for "end of pattern" is a check against cd->end_pattern in the main loop, |
| 1119 |
|
instead of looking for a binary zero. This means that the special first-pass |
| 1120 |
|
call can adjust cd->end_pattern temporarily. (Checks for binary zero while |
| 1121 |
|
processing items within the loop are OK, because afterwards the main loop will |
| 1122 |
|
terminate.) |
| 1123 |
|
|
| 1124 |
Arguments: |
Arguments: |
| 1125 |
ptrptr address of the current character pointer (updated) |
ptrptr address of the current character pointer (updated) |
| 1127 |
name name to seek, or NULL if seeking a numbered subpattern |
name name to seek, or NULL if seeking a numbered subpattern |
| 1128 |
lorn name length, or subpattern number if name is NULL |
lorn name length, or subpattern number if name is NULL |
| 1129 |
xmode TRUE if we are in /x mode |
xmode TRUE if we are in /x mode |
| 1130 |
|
utf8 TRUE if we are in UTF-8 mode |
| 1131 |
count pointer to the current capturing subpattern number (updated) |
count pointer to the current capturing subpattern number (updated) |
| 1132 |
|
|
| 1133 |
Returns: the number of the named subpattern, or -1 if not found |
Returns: the number of the named subpattern, or -1 if not found |
| 1135 |
|
|
| 1136 |
static int |
static int |
| 1137 |
find_parens_sub(uschar **ptrptr, compile_data *cd, const uschar *name, int lorn, |
find_parens_sub(uschar **ptrptr, compile_data *cd, const uschar *name, int lorn, |
| 1138 |
BOOL xmode, int *count) |
BOOL xmode, BOOL utf8, int *count) |
| 1139 |
{ |
{ |
| 1140 |
uschar *ptr = *ptrptr; |
uschar *ptr = *ptrptr; |
| 1141 |
int start_count = *count; |
int start_count = *count; |
| 1147 |
|
|
| 1148 |
if (ptr[0] == CHAR_LEFT_PARENTHESIS) |
if (ptr[0] == CHAR_LEFT_PARENTHESIS) |
| 1149 |
{ |
{ |
| 1150 |
if (ptr[1] == CHAR_QUESTION_MARK && |
/* Handle specials such as (*SKIP) or (*UTF8) etc. */ |
| 1151 |
ptr[2] == CHAR_VERTICAL_LINE) |
|
| 1152 |
|
if (ptr[1] == CHAR_ASTERISK) ptr += 2; |
| 1153 |
|
|
| 1154 |
|
/* Handle a normal, unnamed capturing parenthesis. */ |
| 1155 |
|
|
| 1156 |
|
else if (ptr[1] != CHAR_QUESTION_MARK) |
| 1157 |
|
{ |
| 1158 |
|
*count += 1; |
| 1159 |
|
if (name == NULL && *count == lorn) return *count; |
| 1160 |
|
ptr++; |
| 1161 |
|
} |
| 1162 |
|
|
| 1163 |
|
/* All cases now have (? at the start. Remember when we are in a group |
| 1164 |
|
where the parenthesis numbers are duplicated. */ |
| 1165 |
|
|
| 1166 |
|
else if (ptr[2] == CHAR_VERTICAL_LINE) |
| 1167 |
{ |
{ |
| 1168 |
ptr += 3; |
ptr += 3; |
| 1169 |
dup_parens = TRUE; |
dup_parens = TRUE; |
| 1170 |
} |
} |
| 1171 |
|
|
| 1172 |
/* Handle a normal, unnamed capturing parenthesis */ |
/* Handle comments; all characters are allowed until a ket is reached. */ |
| 1173 |
|
|
| 1174 |
else if (ptr[1] != CHAR_QUESTION_MARK && ptr[1] != CHAR_ASTERISK) |
else if (ptr[2] == CHAR_NUMBER_SIGN) |
| 1175 |
{ |
{ |
| 1176 |
*count += 1; |
for (ptr += 3; *ptr != 0; ptr++) if (*ptr == CHAR_RIGHT_PARENTHESIS) break; |
| 1177 |
if (name == NULL && *count == lorn) return *count; |
goto FAIL_EXIT; |
|
ptr++; |
|
| 1178 |
} |
} |
| 1179 |
|
|
| 1180 |
/* Handle a condition. If it is an assertion, just carry on so that it |
/* Handle a condition. If it is an assertion, just carry on so that it |
| 1181 |
is processed as normal. If not, skip to the closing parenthesis of the |
is processed as normal. If not, skip to the closing parenthesis of the |
| 1182 |
condition (there can't be any nested parens. */ |
condition (there can't be any nested parens). */ |
| 1183 |
|
|
| 1184 |
else if (ptr[2] == CHAR_LEFT_PARENTHESIS) |
else if (ptr[2] == CHAR_LEFT_PARENTHESIS) |
| 1185 |
{ |
{ |
| 1191 |
} |
} |
| 1192 |
} |
} |
| 1193 |
|
|
| 1194 |
/* We have either (? or (* and not a condition */ |
/* Start with (? but not a condition. */ |
| 1195 |
|
|
| 1196 |
else |
else |
| 1197 |
{ |
{ |
| 1214 |
if (name != NULL && lorn == ptr - thisname && |
if (name != NULL && lorn == ptr - thisname && |
| 1215 |
strncmp((const char *)name, (const char *)thisname, lorn) == 0) |
strncmp((const char *)name, (const char *)thisname, lorn) == 0) |
| 1216 |
return *count; |
return *count; |
| 1217 |
term++; |
term++; |
| 1218 |
} |
} |
| 1219 |
} |
} |
| 1220 |
} |
} |
| 1221 |
|
|
| 1222 |
/* Past any initial parenthesis handling, scan for parentheses or vertical |
/* Past any initial parenthesis handling, scan for parentheses or vertical |
| 1223 |
bars. */ |
bars. Stop if we get to cd->end_pattern. Note that this is important for the |
| 1224 |
|
first-pass call when this value is temporarily adjusted to stop at the current |
| 1225 |
|
position. So DO NOT change this to a test for binary zero. */ |
| 1226 |
|
|
| 1227 |
for (; *ptr != 0; ptr++) |
for (; ptr < cd->end_pattern; ptr++) |
| 1228 |
{ |
{ |
| 1229 |
/* Skip over backslashed characters and also entire \Q...\E */ |
/* Skip over backslashed characters and also entire \Q...\E */ |
| 1230 |
|
|
| 1262 |
break; |
break; |
| 1263 |
} |
} |
| 1264 |
else if (!negate_class && ptr[1] == CHAR_CIRCUMFLEX_ACCENT) |
else if (!negate_class && ptr[1] == CHAR_CIRCUMFLEX_ACCENT) |
| 1265 |
{ |
{ |
| 1266 |
negate_class = TRUE; |
negate_class = TRUE; |
| 1267 |
ptr++; |
ptr++; |
| 1268 |
} |
} |
| 1269 |
else break; |
else break; |
| 1270 |
} |
} |
| 1271 |
|
|
| 1298 |
|
|
| 1299 |
if (xmode && *ptr == CHAR_NUMBER_SIGN) |
if (xmode && *ptr == CHAR_NUMBER_SIGN) |
| 1300 |
{ |
{ |
| 1301 |
while (*(++ptr) != 0 && *ptr != CHAR_NL) {}; |
ptr++; |
| 1302 |
|
while (*ptr != 0) |
| 1303 |
|
{ |
| 1304 |
|
if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; } |
| 1305 |
|
ptr++; |
| 1306 |
|
#ifdef SUPPORT_UTF8 |
| 1307 |
|
if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++; |
| 1308 |
|
#endif |
| 1309 |
|
} |
| 1310 |
if (*ptr == 0) goto FAIL_EXIT; |
if (*ptr == 0) goto FAIL_EXIT; |
| 1311 |
continue; |
continue; |
| 1312 |
} |
} |
| 1315 |
|
|
| 1316 |
if (*ptr == CHAR_LEFT_PARENTHESIS) |
if (*ptr == CHAR_LEFT_PARENTHESIS) |
| 1317 |
{ |
{ |
| 1318 |
int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, count); |
int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf8, count); |
| 1319 |
if (rc > 0) return rc; |
if (rc > 0) return rc; |
| 1320 |
if (*ptr == 0) goto FAIL_EXIT; |
if (*ptr == 0) goto FAIL_EXIT; |
| 1321 |
} |
} |
| 1323 |
else if (*ptr == CHAR_RIGHT_PARENTHESIS) |
else if (*ptr == CHAR_RIGHT_PARENTHESIS) |
| 1324 |
{ |
{ |
| 1325 |
if (dup_parens && *count < hwm_count) *count = hwm_count; |
if (dup_parens && *count < hwm_count) *count = hwm_count; |
| 1326 |
*ptrptr = ptr; |
goto FAIL_EXIT; |
|
return -1; |
|
| 1327 |
} |
} |
| 1328 |
|
|
| 1329 |
else if (*ptr == CHAR_VERTICAL_LINE && dup_parens) |
else if (*ptr == CHAR_VERTICAL_LINE && dup_parens) |
| 1361 |
name name to seek, or NULL if seeking a numbered subpattern |
name name to seek, or NULL if seeking a numbered subpattern |
| 1362 |
lorn name length, or subpattern number if name is NULL |
lorn name length, or subpattern number if name is NULL |
| 1363 |
xmode TRUE if we are in /x mode |
xmode TRUE if we are in /x mode |
| 1364 |
|
utf8 TRUE if we are in UTF-8 mode |
| 1365 |
|
|
| 1366 |
Returns: the number of the found subpattern, or -1 if not found |
Returns: the number of the found subpattern, or -1 if not found |
| 1367 |
*/ |
*/ |
| 1368 |
|
|
| 1369 |
static int |
static int |
| 1370 |
find_parens(compile_data *cd, const uschar *name, int lorn, BOOL xmode) |
find_parens(compile_data *cd, const uschar *name, int lorn, BOOL xmode, |
| 1371 |
|
BOOL utf8) |
| 1372 |
{ |
{ |
| 1373 |
uschar *ptr = (uschar *)cd->start_pattern; |
uschar *ptr = (uschar *)cd->start_pattern; |
| 1374 |
int count = 0; |
int count = 0; |
| 1381 |
|
|
| 1382 |
for (;;) |
for (;;) |
| 1383 |
{ |
{ |
| 1384 |
rc = find_parens_sub(&ptr, cd, name, lorn, xmode, &count); |
rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf8, &count); |
| 1385 |
if (rc > 0 || *ptr++ == 0) break; |
if (rc > 0 || *ptr++ == 0) break; |
| 1386 |
} |
} |
| 1387 |
|
|
| 1397 |
|
|
| 1398 |
/* This is called by several functions that scan a compiled expression looking |
/* This is called by several functions that scan a compiled expression looking |
| 1399 |
for a fixed first character, or an anchoring op code etc. It skips over things |
for a fixed first character, or an anchoring op code etc. It skips over things |
| 1400 |
that do not influence this. For some calls, a change of option is important. |
that do not influence this. For some calls, it makes sense to skip negative |
| 1401 |
For some calls, it makes sense to skip negative forward and all backward |
forward and all backward assertions, and also the \b assertion; for others it |
| 1402 |
assertions, and also the \b assertion; for others it does not. |
does not. |
| 1403 |
|
|
| 1404 |
Arguments: |
Arguments: |
| 1405 |
code pointer to the start of the group |
code pointer to the start of the group |
|
options pointer to external options |
|
|
optbit the option bit whose changing is significant, or |
|
|
zero if none are |
|
| 1406 |
skipassert TRUE if certain assertions are to be skipped |
skipassert TRUE if certain assertions are to be skipped |
| 1407 |
|
|
| 1408 |
Returns: pointer to the first significant opcode |
Returns: pointer to the first significant opcode |
| 1409 |
*/ |
*/ |
| 1410 |
|
|
| 1411 |
static const uschar* |
static const uschar* |
| 1412 |
first_significant_code(const uschar *code, int *options, int optbit, |
first_significant_code(const uschar *code, BOOL skipassert) |
|
BOOL skipassert) |
|
| 1413 |
{ |
{ |
| 1414 |
for (;;) |
for (;;) |
| 1415 |
{ |
{ |
| 1416 |
switch ((int)*code) |
switch ((int)*code) |
| 1417 |
{ |
{ |
|
case OP_OPT: |
|
|
if (optbit > 0 && ((int)code[1] & optbit) != (*options & optbit)) |
|
|
*options = (int)code[1]; |
|
|
code += 2; |
|
|
break; |
|
|
|
|
| 1418 |
case OP_ASSERT_NOT: |
case OP_ASSERT_NOT: |
| 1419 |
case OP_ASSERTBACK: |
case OP_ASSERTBACK: |
| 1420 |
case OP_ASSERTBACK_NOT: |
case OP_ASSERTBACK_NOT: |
| 1430 |
|
|
| 1431 |
case OP_CALLOUT: |
case OP_CALLOUT: |
| 1432 |
case OP_CREF: |
case OP_CREF: |
| 1433 |
|
case OP_NCREF: |
| 1434 |
case OP_RREF: |
case OP_RREF: |
| 1435 |
|
case OP_NRREF: |
| 1436 |
case OP_DEF: |
case OP_DEF: |
| 1437 |
code += _pcre_OP_lengths[*code]; |
code += _pcre_OP_lengths[*code]; |
| 1438 |
break; |
break; |
| 1453 |
|
|
| 1454 |
/* Scan a branch and compute the fixed length of subject that will match it, |
/* Scan a branch and compute the fixed length of subject that will match it, |
| 1455 |
if the length is fixed. This is needed for dealing with backward assertions. |
if the length is fixed. This is needed for dealing with backward assertions. |
| 1456 |
In UTF8 mode, the result is in characters rather than bytes. The branch is |
In UTF8 mode, the result is in characters rather than bytes. The branch is |
| 1457 |
temporarily terminated with OP_END when this function is called. |
temporarily terminated with OP_END when this function is called. |
| 1458 |
|
|
| 1459 |
This function is called when a backward assertion is encountered, so that if it |
This function is called when a backward assertion is encountered, so that if it |
| 1460 |
fails, the error message can point to the correct place in the pattern. |
fails, the error message can point to the correct place in the pattern. |
| 1461 |
However, we cannot do this when the assertion contains subroutine calls, |
However, we cannot do this when the assertion contains subroutine calls, |
| 1462 |
because they can be forward references. We solve this by remembering this case |
because they can be forward references. We solve this by remembering this case |
| 1463 |
and doing the check at the end; a flag specifies which mode we are running in. |
and doing the check at the end; a flag specifies which mode we are running in. |
| 1464 |
|
|
| 1465 |
Arguments: |
Arguments: |
| 1466 |
code points to the start of the pattern (the bracket) |
code points to the start of the pattern (the bracket) |
| 1467 |
options the compiling options |
utf8 TRUE in UTF-8 mode |
| 1468 |
atend TRUE if called when the pattern is complete |
atend TRUE if called when the pattern is complete |
| 1469 |
cd the "compile data" structure |
cd the "compile data" structure |
| 1470 |
|
|
| 1471 |
Returns: the fixed length, |
Returns: the fixed length, |
| 1472 |
or -1 if there is no fixed length, |
or -1 if there is no fixed length, |
| 1473 |
or -2 if \C was encountered |
or -2 if \C was encountered |
| 1474 |
or -3 if an OP_RECURSE item was encountered and atend is FALSE |
or -3 if an OP_RECURSE item was encountered and atend is FALSE |
| 1475 |
*/ |
*/ |
| 1476 |
|
|
| 1477 |
static int |
static int |
| 1478 |
find_fixedlength(uschar *code, int options, BOOL atend, compile_data *cd) |
find_fixedlength(uschar *code, BOOL utf8, BOOL atend, compile_data *cd) |
| 1479 |
{ |
{ |
| 1480 |
int length = -1; |
int length = -1; |
| 1481 |
|
|
| 1492 |
register int op = *cc; |
register int op = *cc; |
| 1493 |
switch (op) |
switch (op) |
| 1494 |
{ |
{ |
| 1495 |
|
/* We only need to continue for OP_CBRA (normal capturing bracket) and |
| 1496 |
|
OP_BRA (normal non-capturing bracket) because the other variants of these |
| 1497 |
|
opcodes are all concerned with unlimited repeated groups, which of course |
| 1498 |
|
are not of fixed length. They will cause a -1 response from the default |
| 1499 |
|
case of this switch. */ |
| 1500 |
|
|
| 1501 |
case OP_CBRA: |
case OP_CBRA: |
| 1502 |
case OP_BRA: |
case OP_BRA: |
| 1503 |
case OP_ONCE: |
case OP_ONCE: |
| 1504 |
case OP_COND: |
case OP_COND: |
| 1505 |
d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), options, atend, cd); |
d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd); |
| 1506 |
if (d < 0) return d; |
if (d < 0) return d; |
| 1507 |
branchlength += d; |
branchlength += d; |
| 1508 |
do cc += GET(cc, 1); while (*cc == OP_ALT); |
do cc += GET(cc, 1); while (*cc == OP_ALT); |
| 1511 |
|
|
| 1512 |
/* Reached end of a branch; if it's a ket it is the end of a nested |
/* Reached end of a branch; if it's a ket it is the end of a nested |
| 1513 |
call. If it's ALT it is an alternation in a nested call. If it is |
call. If it's ALT it is an alternation in a nested call. If it is |
| 1514 |
END it's the end of the outer call. All can be handled by the same code. */ |
END it's the end of the outer call. All can be handled by the same code. |
| 1515 |
|
Note that we must not include the OP_KETRxxx opcodes here, because they |
| 1516 |
|
all imply an unlimited repeat. */ |
| 1517 |
|
|
| 1518 |
case OP_ALT: |
case OP_ALT: |
| 1519 |
case OP_KET: |
case OP_KET: |
|
case OP_KETRMAX: |
|
|
case OP_KETRMIN: |
|
| 1520 |
case OP_END: |
case OP_END: |
| 1521 |
if (length < 0) length = branchlength; |
if (length < 0) length = branchlength; |
| 1522 |
else if (length != branchlength) return -1; |
else if (length != branchlength) return -1; |
| 1524 |
cc += 1 + LINK_SIZE; |
cc += 1 + LINK_SIZE; |
| 1525 |
branchlength = 0; |
branchlength = 0; |
| 1526 |
break; |
break; |
| 1527 |
|
|
| 1528 |
/* A true recursion implies not fixed length, but a subroutine call may |
/* A true recursion implies not fixed length, but a subroutine call may |
| 1529 |
be OK. If the subroutine is a forward reference, we can't deal with |
be OK. If the subroutine is a forward reference, we can't deal with |
| 1530 |
it until the end of the pattern, so return -3. */ |
it until the end of the pattern, so return -3. */ |
| 1531 |
|
|
| 1532 |
case OP_RECURSE: |
case OP_RECURSE: |
| 1533 |
if (!atend) return -3; |
if (!atend) return -3; |
| 1534 |
cs = ce = (uschar *)cd->start_code + GET(cc, 1); /* Start subpattern */ |
cs = ce = (uschar *)cd->start_code + GET(cc, 1); /* Start subpattern */ |
| 1535 |
do ce += GET(ce, 1); while (*ce == OP_ALT); /* End subpattern */ |
do ce += GET(ce, 1); while (*ce == OP_ALT); /* End subpattern */ |
| 1536 |
if (cc > cs && cc < ce) return -1; /* Recursion */ |
if (cc > cs && cc < ce) return -1; /* Recursion */ |
| 1537 |
d = find_fixedlength(cs + 2, options, atend, cd); |
d = find_fixedlength(cs + 2, utf8, atend, cd); |
| 1538 |
if (d < 0) return d; |
if (d < 0) return d; |
| 1539 |
branchlength += d; |
branchlength += d; |
| 1540 |
cc += 1 + LINK_SIZE; |
cc += 1 + LINK_SIZE; |
| 1541 |
break; |
break; |
| 1542 |
|
|
| 1543 |
/* Skip over assertive subpatterns */ |
/* Skip over assertive subpatterns */ |
| 1544 |
|
|
| 1553 |
|
|
| 1554 |
case OP_REVERSE: |
case OP_REVERSE: |
| 1555 |
case OP_CREF: |
case OP_CREF: |
| 1556 |
|
case OP_NCREF: |
| 1557 |
case OP_RREF: |
case OP_RREF: |
| 1558 |
|
case OP_NRREF: |
| 1559 |
case OP_DEF: |
case OP_DEF: |
|
case OP_OPT: |
|
| 1560 |
case OP_CALLOUT: |
case OP_CALLOUT: |
| 1561 |
case OP_SOD: |
case OP_SOD: |
| 1562 |
case OP_SOM: |
case OP_SOM: |
| 1563 |
|
case OP_SET_SOM: |
| 1564 |
case OP_EOD: |
case OP_EOD: |
| 1565 |
case OP_EODN: |
case OP_EODN: |
| 1566 |
case OP_CIRC: |
case OP_CIRC: |
| 1567 |
|
case OP_CIRCM: |
| 1568 |
case OP_DOLL: |
case OP_DOLL: |
| 1569 |
|
case OP_DOLLM: |
| 1570 |
case OP_NOT_WORD_BOUNDARY: |
case OP_NOT_WORD_BOUNDARY: |
| 1571 |
case OP_WORD_BOUNDARY: |
case OP_WORD_BOUNDARY: |
| 1572 |
cc += _pcre_OP_lengths[*cc]; |
cc += _pcre_OP_lengths[*cc]; |
| 1575 |
/* Handle literal characters */ |
/* Handle literal characters */ |
| 1576 |
|
|
| 1577 |
case OP_CHAR: |
case OP_CHAR: |
| 1578 |
case OP_CHARNC: |
case OP_CHARI: |
| 1579 |
case OP_NOT: |
case OP_NOT: |
| 1580 |
|
case OP_NOTI: |
| 1581 |
branchlength++; |
branchlength++; |
| 1582 |
cc += 2; |
cc += 2; |
| 1583 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 1584 |
if ((options & PCRE_UTF8) != 0 && cc[-1] >= 0xc0) |
if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f]; |
|
cc += _pcre_utf8_table4[cc[-1] & 0x3f]; |
|
| 1585 |
#endif |
#endif |
| 1586 |
break; |
break; |
| 1587 |
|
|
| 1592 |
branchlength += GET2(cc,1); |
branchlength += GET2(cc,1); |
| 1593 |
cc += 4; |
cc += 4; |
| 1594 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 1595 |
if ((options & PCRE_UTF8) != 0 && cc[-1] >= 0xc0) |
if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f]; |
|
cc += _pcre_utf8_table4[cc[-1] & 0x3f]; |
|
| 1596 |
#endif |
#endif |
| 1597 |
break; |
break; |
| 1598 |
|
|
| 1676 |
|
|
| 1677 |
/* This little function scans through a compiled pattern until it finds a |
/* This little function scans through a compiled pattern until it finds a |
| 1678 |
capturing bracket with the given number, or, if the number is negative, an |
capturing bracket with the given number, or, if the number is negative, an |
| 1679 |
instance of OP_REVERSE for a lookbehind. The function is global in the C sense |
instance of OP_REVERSE for a lookbehind. The function is global in the C sense |
| 1680 |
so that it can be called from pcre_study() when finding the minimum matching |
so that it can be called from pcre_study() when finding the minimum matching |
| 1681 |
length. |
length. |
| 1682 |
|
|
| 1683 |
Arguments: |
Arguments: |
| 1701 |
the table is zero; the actual length is stored in the compiled code. */ |
the table is zero; the actual length is stored in the compiled code. */ |
| 1702 |
|
|
| 1703 |
if (c == OP_XCLASS) code += GET(code, 1); |
if (c == OP_XCLASS) code += GET(code, 1); |
| 1704 |
|
|
| 1705 |
/* Handle recursion */ |
/* Handle recursion */ |
| 1706 |
|
|
| 1707 |
else if (c == OP_REVERSE) |
else if (c == OP_REVERSE) |
| 1708 |
{ |
{ |
| 1709 |
if (number < 0) return (uschar *)code; |
if (number < 0) return (uschar *)code; |
| 1710 |
code += _pcre_OP_lengths[c]; |
code += _pcre_OP_lengths[c]; |
| 1711 |
} |
} |
| 1712 |
|
|
| 1713 |
/* Handle capturing bracket */ |
/* Handle capturing bracket */ |
| 1714 |
|
|
| 1715 |
else if (c == OP_CBRA) |
else if (c == OP_CBRA || c == OP_SCBRA || |
| 1716 |
|
c == OP_CBRAPOS || c == OP_SCBRAPOS) |
| 1717 |
{ |
{ |
| 1718 |
int n = GET2(code, 1+LINK_SIZE); |
int n = GET2(code, 1+LINK_SIZE); |
| 1719 |
if (n == number) return (uschar *)code; |
if (n == number) return (uschar *)code; |
| 1722 |
|
|
| 1723 |
/* Otherwise, we can get the item's length from the table, except that for |
/* Otherwise, we can get the item's length from the table, except that for |
| 1724 |
repeated character types, we have to test for \p and \P, which have an extra |
repeated character types, we have to test for \p and \P, which have an extra |
| 1725 |
two bytes of parameters. */ |
two bytes of parameters, and for MARK/PRUNE/SKIP/THEN with an argument, we |
| 1726 |
|
must add in its length. */ |
| 1727 |
|
|
| 1728 |
else |
else |
| 1729 |
{ |
{ |
| 1747 |
case OP_TYPEPOSUPTO: |
case OP_TYPEPOSUPTO: |
| 1748 |
if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2; |
if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2; |
| 1749 |
break; |
break; |
| 1750 |
|
|
| 1751 |
|
case OP_MARK: |
| 1752 |
|
case OP_PRUNE_ARG: |
| 1753 |
|
case OP_SKIP_ARG: |
| 1754 |
|
code += code[1]; |
| 1755 |
|
break; |
| 1756 |
|
|
| 1757 |
|
case OP_THEN_ARG: |
| 1758 |
|
code += code[1+LINK_SIZE]; |
| 1759 |
|
break; |
| 1760 |
} |
} |
| 1761 |
|
|
| 1762 |
/* Add in the fixed length from the table */ |
/* Add in the fixed length from the table */ |
| 1771 |
if (utf8) switch(c) |
if (utf8) switch(c) |
| 1772 |
{ |
{ |
| 1773 |
case OP_CHAR: |
case OP_CHAR: |
| 1774 |
case OP_CHARNC: |
case OP_CHARI: |
| 1775 |
case OP_EXACT: |
case OP_EXACT: |
| 1776 |
|
case OP_EXACTI: |
| 1777 |
case OP_UPTO: |
case OP_UPTO: |
| 1778 |
|
case OP_UPTOI: |
| 1779 |
case OP_MINUPTO: |
case OP_MINUPTO: |
| 1780 |
|
case OP_MINUPTOI: |
| 1781 |
case OP_POSUPTO: |
case OP_POSUPTO: |
| 1782 |
|
case OP_POSUPTOI: |
| 1783 |
case OP_STAR: |
case OP_STAR: |
| 1784 |
|
case OP_STARI: |
| 1785 |
case OP_MINSTAR: |
case OP_MINSTAR: |
| 1786 |
|
case OP_MINSTARI: |
| 1787 |
case OP_POSSTAR: |
case OP_POSSTAR: |
| 1788 |
|
case OP_POSSTARI: |
| 1789 |
case OP_PLUS: |
case OP_PLUS: |
| 1790 |
|
case OP_PLUSI: |
| 1791 |
case OP_MINPLUS: |
case OP_MINPLUS: |
| 1792 |
|
case OP_MINPLUSI: |
| 1793 |
case OP_POSPLUS: |
case OP_POSPLUS: |
| 1794 |
|
case OP_POSPLUSI: |
| 1795 |
case OP_QUERY: |
case OP_QUERY: |
| 1796 |
|
case OP_QUERYI: |
| 1797 |
case OP_MINQUERY: |
case OP_MINQUERY: |
| 1798 |
|
case OP_MINQUERYI: |
| 1799 |
case OP_POSQUERY: |
case OP_POSQUERY: |
| 1800 |
|
case OP_POSQUERYI: |
| 1801 |
if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f]; |
if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f]; |
| 1802 |
break; |
break; |
| 1803 |
} |
} |
| 1841 |
|
|
| 1842 |
/* Otherwise, we can get the item's length from the table, except that for |
/* Otherwise, we can get the item's length from the table, except that for |
| 1843 |
repeated character types, we have to test for \p and \P, which have an extra |
repeated character types, we have to test for \p and \P, which have an extra |
| 1844 |
two bytes of parameters. */ |
two bytes of parameters, and for MARK/PRUNE/SKIP/THEN with an argument, we |
| 1845 |
|
must add in its length. */ |
| 1846 |
|
|
| 1847 |
else |
else |
| 1848 |
{ |
{ |
| 1866 |
case OP_TYPEEXACT: |
case OP_TYPEEXACT: |
| 1867 |
if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2; |
if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2; |
| 1868 |
break; |
break; |
| 1869 |
|
|
| 1870 |
|
case OP_MARK: |
| 1871 |
|
case OP_PRUNE_ARG: |
| 1872 |
|
case OP_SKIP_ARG: |
| 1873 |
|
code += code[1]; |
| 1874 |
|
break; |
| 1875 |
|
|
| 1876 |
|
case OP_THEN_ARG: |
| 1877 |
|
code += code[1+LINK_SIZE]; |
| 1878 |
|
break; |
| 1879 |
} |
} |
| 1880 |
|
|
| 1881 |
/* Add in the fixed length from the table */ |
/* Add in the fixed length from the table */ |
| 1890 |
if (utf8) switch(c) |
if (utf8) switch(c) |
| 1891 |
{ |
{ |
| 1892 |
case OP_CHAR: |
case OP_CHAR: |
| 1893 |
case OP_CHARNC: |
case OP_CHARI: |
| 1894 |
case OP_EXACT: |
case OP_EXACT: |
| 1895 |
|
case OP_EXACTI: |
| 1896 |
case OP_UPTO: |
case OP_UPTO: |
| 1897 |
|
case OP_UPTOI: |
| 1898 |
case OP_MINUPTO: |
case OP_MINUPTO: |
| 1899 |
|
case OP_MINUPTOI: |
| 1900 |
case OP_POSUPTO: |
case OP_POSUPTO: |
| 1901 |
|
case OP_POSUPTOI: |
| 1902 |
case OP_STAR: |
case OP_STAR: |
| 1903 |
|
case OP_STARI: |
| 1904 |
case OP_MINSTAR: |
case OP_MINSTAR: |
| 1905 |
|
case OP_MINSTARI: |
| 1906 |
case OP_POSSTAR: |
case OP_POSSTAR: |
| 1907 |
|
case OP_POSSTARI: |
| 1908 |
case OP_PLUS: |
case OP_PLUS: |
| 1909 |
|
case OP_PLUSI: |
| 1910 |
case OP_MINPLUS: |
case OP_MINPLUS: |
| 1911 |
|
case OP_MINPLUSI: |
| 1912 |
case OP_POSPLUS: |
case OP_POSPLUS: |
| 1913 |
|
case OP_POSPLUSI: |
| 1914 |
case OP_QUERY: |
case OP_QUERY: |
| 1915 |
|
case OP_QUERYI: |
| 1916 |
case OP_MINQUERY: |
case OP_MINQUERY: |
| 1917 |
|
case OP_MINQUERYI: |
| 1918 |
case OP_POSQUERY: |
case OP_POSQUERY: |
| 1919 |
|
case OP_POSQUERYI: |
| 1920 |
if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f]; |
if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f]; |
| 1921 |
break; |
break; |
| 1922 |
} |
} |
| 1945 |
code points to start of search |
code points to start of search |
| 1946 |
endcode points to where to stop |
endcode points to where to stop |
| 1947 |
utf8 TRUE if in UTF8 mode |
utf8 TRUE if in UTF8 mode |
| 1948 |
|
cd contains pointers to tables etc. |
| 1949 |
|
|
| 1950 |
Returns: TRUE if what is matched could be empty |
Returns: TRUE if what is matched could be empty |
| 1951 |
*/ |
*/ |
| 1952 |
|
|
| 1953 |
static BOOL |
static BOOL |
| 1954 |
could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8) |
could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8, |
| 1955 |
|
compile_data *cd) |
| 1956 |
{ |
{ |
| 1957 |
register int c; |
register int c; |
| 1958 |
for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE); |
for (code = first_significant_code(code + _pcre_OP_lengths[*code], TRUE); |
| 1959 |
code < endcode; |
code < endcode; |
| 1960 |
code = first_significant_code(code + _pcre_OP_lengths[c], NULL, 0, TRUE)) |
code = first_significant_code(code + _pcre_OP_lengths[c], TRUE)) |
| 1961 |
{ |
{ |
| 1962 |
const uschar *ccode; |
const uschar *ccode; |
| 1963 |
|
|
| 1973 |
continue; |
continue; |
| 1974 |
} |
} |
| 1975 |
|
|
| 1976 |
|
/* For a recursion/subroutine call, if its end has been reached, which |
| 1977 |
|
implies a subroutine call, we can scan it. */ |
| 1978 |
|
|
| 1979 |
|
if (c == OP_RECURSE) |
| 1980 |
|
{ |
| 1981 |
|
BOOL empty_branch = FALSE; |
| 1982 |
|
const uschar *scode = cd->start_code + GET(code, 1); |
| 1983 |
|
if (GET(scode, 1) == 0) return TRUE; /* Unclosed */ |
| 1984 |
|
do |
| 1985 |
|
{ |
| 1986 |
|
if (could_be_empty_branch(scode, endcode, utf8, cd)) |
| 1987 |
|
{ |
| 1988 |
|
empty_branch = TRUE; |
| 1989 |
|
break; |
| 1990 |
|
} |
| 1991 |
|
scode += GET(scode, 1); |
| 1992 |
|
} |
| 1993 |
|
while (*scode == OP_ALT); |
| 1994 |
|
if (!empty_branch) return FALSE; /* All branches are non-empty */ |
| 1995 |
|
continue; |
| 1996 |
|
} |
| 1997 |
|
|
| 1998 |
/* Groups with zero repeats can of course be empty; skip them. */ |
/* Groups with zero repeats can of course be empty; skip them. */ |
| 1999 |
|
|
| 2000 |
if (c == OP_BRAZERO || c == OP_BRAMINZERO || c == OP_SKIPZERO) |
if (c == OP_BRAZERO || c == OP_BRAMINZERO || c == OP_SKIPZERO || |
| 2001 |
|
c == OP_BRAPOSZERO) |
| 2002 |
{ |
{ |
| 2003 |
code += _pcre_OP_lengths[c]; |
code += _pcre_OP_lengths[c]; |
| 2004 |
do code += GET(code, 1); while (*code == OP_ALT); |
do code += GET(code, 1); while (*code == OP_ALT); |
| 2006 |
continue; |
continue; |
| 2007 |
} |
} |
| 2008 |
|
|
| 2009 |
|
/* A nested group that is already marked as "could be empty" can just be |
| 2010 |
|
skipped. */ |
| 2011 |
|
|
| 2012 |
|
if (c == OP_SBRA || c == OP_SBRAPOS || |
| 2013 |
|
c == OP_SCBRA || c == OP_SCBRAPOS) |
| 2014 |
|
{ |
| 2015 |
|
do code += GET(code, 1); while (*code == OP_ALT); |
| 2016 |
|
c = *code; |
| 2017 |
|
continue; |
| 2018 |
|
} |
| 2019 |
|
|
| 2020 |
/* For other groups, scan the branches. */ |
/* For other groups, scan the branches. */ |
| 2021 |
|
|
| 2022 |
if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE || c == OP_COND) |
if (c == OP_BRA || c == OP_BRAPOS || |
| 2023 |
|
c == OP_CBRA || c == OP_CBRAPOS || |
| 2024 |
|
c == OP_ONCE || c == OP_COND) |
| 2025 |
{ |
{ |
| 2026 |
BOOL empty_branch; |
BOOL empty_branch; |
| 2027 |
if (GET(code, 1) == 0) return TRUE; /* Hit unclosed bracket */ |
if (GET(code, 1) == 0) return TRUE; /* Hit unclosed bracket */ |
| 2037 |
empty_branch = FALSE; |
empty_branch = FALSE; |
| 2038 |
do |
do |
| 2039 |
{ |
{ |
| 2040 |
if (!empty_branch && could_be_empty_branch(code, endcode, utf8)) |
if (!empty_branch && could_be_empty_branch(code, endcode, utf8, cd)) |
| 2041 |
empty_branch = TRUE; |
empty_branch = TRUE; |
| 2042 |
code += GET(code, 1); |
code += GET(code, 1); |
| 2043 |
} |
} |
| 2108 |
case OP_ALLANY: |
case OP_ALLANY: |
| 2109 |
case OP_ANYBYTE: |
case OP_ANYBYTE: |
| 2110 |
case OP_CHAR: |
case OP_CHAR: |
| 2111 |
case OP_CHARNC: |
case OP_CHARI: |
| 2112 |
case OP_NOT: |
case OP_NOT: |
| 2113 |
|
case OP_NOTI: |
| 2114 |
case OP_PLUS: |
case OP_PLUS: |
| 2115 |
case OP_MINPLUS: |
case OP_MINPLUS: |
| 2116 |
case OP_POSPLUS: |
case OP_POSPLUS: |
| 2150 |
case OP_KET: |
case OP_KET: |
| 2151 |
case OP_KETRMAX: |
case OP_KETRMAX: |
| 2152 |
case OP_KETRMIN: |
case OP_KETRMIN: |
| 2153 |
|
case OP_KETRPOS: |
| 2154 |
case OP_ALT: |
case OP_ALT: |
| 2155 |
return TRUE; |
return TRUE; |
| 2156 |
|
|
| 2159 |
|
|
| 2160 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 2161 |
case OP_STAR: |
case OP_STAR: |
| 2162 |
|
case OP_STARI: |
| 2163 |
case OP_MINSTAR: |
case OP_MINSTAR: |
| 2164 |
|
case OP_MINSTARI: |
| 2165 |
case OP_POSSTAR: |
case OP_POSSTAR: |
| 2166 |
|
case OP_POSSTARI: |
| 2167 |
case OP_QUERY: |
case OP_QUERY: |
| 2168 |
|
case OP_QUERYI: |
| 2169 |
case OP_MINQUERY: |
case OP_MINQUERY: |
| 2170 |
|
case OP_MINQUERYI: |
| 2171 |
case OP_POSQUERY: |
case OP_POSQUERY: |
| 2172 |
|
case OP_POSQUERYI: |
| 2173 |
if (utf8 && code[1] >= 0xc0) code += _pcre_utf8_table4[code[1] & 0x3f]; |
if (utf8 && code[1] >= 0xc0) code += _pcre_utf8_table4[code[1] & 0x3f]; |
| 2174 |
break; |
break; |
| 2175 |
|
|
| 2176 |
case OP_UPTO: |
case OP_UPTO: |
| 2177 |
|
case OP_UPTOI: |
| 2178 |
case OP_MINUPTO: |
case OP_MINUPTO: |
| 2179 |
|
case OP_MINUPTOI: |
| 2180 |
case OP_POSUPTO: |
case OP_POSUPTO: |
| 2181 |
|
case OP_POSUPTOI: |
| 2182 |
if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f]; |
if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f]; |
| 2183 |
break; |
break; |
| 2184 |
#endif |
#endif |
| 2185 |
|
|
| 2186 |
|
/* MARK, and PRUNE/SKIP/THEN with an argument must skip over the argument |
| 2187 |
|
string. */ |
| 2188 |
|
|
| 2189 |
|
case OP_MARK: |
| 2190 |
|
case OP_PRUNE_ARG: |
| 2191 |
|
case OP_SKIP_ARG: |
| 2192 |
|
code += code[1]; |
| 2193 |
|
break; |
| 2194 |
|
|
| 2195 |
|
case OP_THEN_ARG: |
| 2196 |
|
code += code[1+LINK_SIZE]; |
| 2197 |
|
break; |
| 2198 |
|
|
| 2199 |
|
/* None of the remaining opcodes are required to match a character. */ |
| 2200 |
|
|
| 2201 |
|
default: |
| 2202 |
|
break; |
| 2203 |
} |
} |
| 2204 |
} |
} |
| 2205 |
|
|
| 2222 |
endcode points to where to stop (current RECURSE item) |
endcode points to where to stop (current RECURSE item) |
| 2223 |
bcptr points to the chain of current (unclosed) branch starts |
bcptr points to the chain of current (unclosed) branch starts |
| 2224 |
utf8 TRUE if in UTF-8 mode |
utf8 TRUE if in UTF-8 mode |
| 2225 |
|
cd pointers to tables etc |
| 2226 |
|
|
| 2227 |
Returns: TRUE if what is matched could be empty |
Returns: TRUE if what is matched could be empty |
| 2228 |
*/ |
*/ |
| 2229 |
|
|
| 2230 |
static BOOL |
static BOOL |
| 2231 |
could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr, |
could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr, |
| 2232 |
BOOL utf8) |
BOOL utf8, compile_data *cd) |
| 2233 |
{ |
{ |
| 2234 |
while (bcptr != NULL && bcptr->current >= code) |
while (bcptr != NULL && bcptr->current_branch >= code) |
| 2235 |
{ |
{ |
| 2236 |
if (!could_be_empty_branch(bcptr->current, endcode, utf8)) return FALSE; |
if (!could_be_empty_branch(bcptr->current_branch, endcode, utf8, cd)) |
| 2237 |
|
return FALSE; |
| 2238 |
bcptr = bcptr->outer; |
bcptr = bcptr->outer; |
| 2239 |
} |
} |
| 2240 |
return TRUE; |
return TRUE; |
| 2416 |
{ |
{ |
| 2417 |
*code++ = OP_CALLOUT; |
*code++ = OP_CALLOUT; |
| 2418 |
*code++ = 255; |
*code++ = 255; |
| 2419 |
PUT(code, 0, ptr - cd->start_pattern); /* Pattern offset */ |
PUT(code, 0, (int)(ptr - cd->start_pattern)); /* Pattern offset */ |
| 2420 |
PUT(code, LINK_SIZE, 0); /* Default length */ |
PUT(code, LINK_SIZE, 0); /* Default length */ |
| 2421 |
return code + 2*LINK_SIZE; |
return code + 2*LINK_SIZE; |
| 2422 |
} |
} |
| 2423 |
|
|
| 2442 |
static void |
static void |
| 2443 |
complete_callout(uschar *previous_callout, const uschar *ptr, compile_data *cd) |
complete_callout(uschar *previous_callout, const uschar *ptr, compile_data *cd) |
| 2444 |
{ |
{ |
| 2445 |
int length = ptr - cd->start_pattern - GET(previous_callout, 2); |
int length = (int)(ptr - cd->start_pattern - GET(previous_callout, 2)); |
| 2446 |
PUT(previous_callout, 2 + LINK_SIZE, length); |
PUT(previous_callout, 2 + LINK_SIZE, length); |
| 2447 |
} |
} |
| 2448 |
|
|
| 2492 |
|
|
| 2493 |
return TRUE; |
return TRUE; |
| 2494 |
} |
} |
| 2495 |
|
|
| 2496 |
|
|
| 2497 |
|
|
| 2498 |
|
/************************************************* |
| 2499 |
|
* Check a character and a property * |
| 2500 |
|
*************************************************/ |
| 2501 |
|
|
| 2502 |
|
/* This function is called by check_auto_possessive() when a property item |
| 2503 |
|
is adjacent to a fixed character. |
| 2504 |
|
|
| 2505 |
|
Arguments: |
| 2506 |
|
c the character |
| 2507 |
|
ptype the property type |
| 2508 |
|
pdata the data for the type |
| 2509 |
|
negated TRUE if it's a negated property (\P or \p{^) |
| 2510 |
|
|
| 2511 |
|
Returns: TRUE if auto-possessifying is OK |
| 2512 |
|
*/ |
| 2513 |
|
|
| 2514 |
|
static BOOL |
| 2515 |
|
check_char_prop(int c, int ptype, int pdata, BOOL negated) |
| 2516 |
|
{ |
| 2517 |
|
const ucd_record *prop = GET_UCD(c); |
| 2518 |
|
switch(ptype) |
| 2519 |
|
{ |
| 2520 |
|
case PT_LAMP: |
| 2521 |
|
return (prop->chartype == ucp_Lu || |
| 2522 |
|
prop->chartype == ucp_Ll || |
| 2523 |
|
prop->chartype == ucp_Lt) == negated; |
| 2524 |
|
|
| 2525 |
|
case PT_GC: |
| 2526 |
|
return (pdata == _pcre_ucp_gentype[prop->chartype]) == negated; |
| 2527 |
|
|
| 2528 |
|
case PT_PC: |
| 2529 |
|
return (pdata == prop->chartype) == negated; |
| 2530 |
|
|
| 2531 |
|
case PT_SC: |
| 2532 |
|
return (pdata == prop->script) == negated; |
| 2533 |
|
|
| 2534 |
|
/* These are specials */ |
| 2535 |
|
|
| 2536 |
|
case PT_ALNUM: |
| 2537 |
|
return (_pcre_ucp_gentype[prop->chartype] == ucp_L || |
| 2538 |
|
_pcre_ucp_gentype[prop->chartype] == ucp_N) == negated; |
| 2539 |
|
|
| 2540 |
|
case PT_SPACE: /* Perl space */ |
| 2541 |
|
return (_pcre_ucp_gentype[prop->chartype] == ucp_Z || |
| 2542 |
|
c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR) |
| 2543 |
|
== negated; |
| 2544 |
|
|
| 2545 |
|
case PT_PXSPACE: /* POSIX space */ |
| 2546 |
|
return (_pcre_ucp_gentype[prop->chartype] == ucp_Z || |
| 2547 |
|
c == CHAR_HT || c == CHAR_NL || c == CHAR_VT || |
| 2548 |
|
c == CHAR_FF || c == CHAR_CR) |
| 2549 |
|
== negated; |
| 2550 |
|
|
| 2551 |
|
case PT_WORD: |
| 2552 |
|
return (_pcre_ucp_gentype[prop->chartype] == ucp_L || |
| 2553 |
|
_pcre_ucp_gentype[prop->chartype] == ucp_N || |
| 2554 |
|
c == CHAR_UNDERSCORE) == negated; |
| 2555 |
|
} |
| 2556 |
|
return FALSE; |
| 2557 |
|
} |
| 2558 |
#endif /* SUPPORT_UCP */ |
#endif /* SUPPORT_UCP */ |
| 2559 |
|
|
| 2560 |
|
|
| 2568 |
sense to automatically possessify the repeated item. |
sense to automatically possessify the repeated item. |
| 2569 |
|
|
| 2570 |
Arguments: |
Arguments: |
| 2571 |
op_code the repeated op code |
previous pointer to the repeated opcode |
|
this data for this item, depends on the opcode |
|
| 2572 |
utf8 TRUE in UTF-8 mode |
utf8 TRUE in UTF-8 mode |
|
utf8_char used for utf8 character bytes, NULL if not relevant |
|
| 2573 |
ptr next character in pattern |
ptr next character in pattern |
| 2574 |
options options bits |
options options bits |
| 2575 |
cd contains pointers to tables etc. |
cd contains pointers to tables etc. |
| 2578 |
*/ |
*/ |
| 2579 |
|
|
| 2580 |
static BOOL |
static BOOL |
| 2581 |
check_auto_possessive(int op_code, int item, BOOL utf8, uschar *utf8_char, |
check_auto_possessive(const uschar *previous, BOOL utf8, const uschar *ptr, |
| 2582 |
const uschar *ptr, int options, compile_data *cd) |
int options, compile_data *cd) |
| 2583 |
{ |
{ |
| 2584 |
int next; |
int c, next; |
| 2585 |
|
int op_code = *previous++; |
| 2586 |
|
|
| 2587 |
/* Skip whitespace and comments in extended mode */ |
/* Skip whitespace and comments in extended mode */ |
| 2588 |
|
|
| 2593 |
while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++; |
while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++; |
| 2594 |
if (*ptr == CHAR_NUMBER_SIGN) |
if (*ptr == CHAR_NUMBER_SIGN) |
| 2595 |
{ |
{ |
| 2596 |
while (*(++ptr) != 0) |
ptr++; |
| 2597 |
|
while (*ptr != 0) |
| 2598 |
|
{ |
| 2599 |
if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; } |
if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; } |
| 2600 |
|
ptr++; |
| 2601 |
|
#ifdef SUPPORT_UTF8 |
| 2602 |
|
if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++; |
| 2603 |
|
#endif |
| 2604 |
|
} |
| 2605 |
} |
} |
| 2606 |
else break; |
else break; |
| 2607 |
} |
} |
| 2637 |
while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++; |
while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++; |
| 2638 |
if (*ptr == CHAR_NUMBER_SIGN) |
if (*ptr == CHAR_NUMBER_SIGN) |
| 2639 |
{ |
{ |
| 2640 |
while (*(++ptr) != 0) |
ptr++; |
| 2641 |
|
while (*ptr != 0) |
| 2642 |
|
{ |
| 2643 |
if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; } |
if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; } |
| 2644 |
|
ptr++; |
| 2645 |
|
#ifdef SUPPORT_UTF8 |
| 2646 |
|
if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++; |
| 2647 |
|
#endif |
| 2648 |
|
} |
| 2649 |
} |
} |
| 2650 |
else break; |
else break; |
| 2651 |
} |
} |
| 2657 |
strncmp((char *)ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0) |
strncmp((char *)ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0) |
| 2658 |
return FALSE; |
return FALSE; |
| 2659 |
|
|
| 2660 |
/* Now compare the next item with the previous opcode. If the previous is a |
/* Now compare the next item with the previous opcode. First, handle cases when |
| 2661 |
positive single character match, "item" either contains the character or, if |
the next item is a character. */ |
|
"item" is greater than 127 in utf8 mode, the character's bytes are in |
|
|
utf8_char. */ |
|
|
|
|
|
|
|
|
/* Handle cases when the next item is a character. */ |
|
| 2662 |
|
|
| 2663 |
if (next >= 0) switch(op_code) |
if (next >= 0) switch(op_code) |
| 2664 |
{ |
{ |
| 2665 |
case OP_CHAR: |
case OP_CHAR: |
| 2666 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 2667 |
if (utf8 && item > 127) { GETCHAR(item, utf8_char); } |
GETCHARTEST(c, previous); |
| 2668 |
#else |
#else |
| 2669 |
(void)(utf8_char); /* Keep compiler happy by referencing function argument */ |
c = *previous; |
| 2670 |
#endif |
#endif |
| 2671 |
return item != next; |
return c != next; |
| 2672 |
|
|
| 2673 |
/* For CHARNC (caseless character) we must check the other case. If we have |
/* For CHARI (caseless character) we must check the other case. If we have |
| 2674 |
Unicode property support, we can use it to test the other case of |
Unicode property support, we can use it to test the other case of |
| 2675 |
high-valued characters. */ |
high-valued characters. */ |
| 2676 |
|
|
| 2677 |
case OP_CHARNC: |
case OP_CHARI: |
| 2678 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 2679 |
if (utf8 && item > 127) { GETCHAR(item, utf8_char); } |
GETCHARTEST(c, previous); |
| 2680 |
|
#else |
| 2681 |
|
c = *previous; |
| 2682 |
#endif |
#endif |
| 2683 |
if (item == next) return FALSE; |
if (c == next) return FALSE; |
| 2684 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 2685 |
if (utf8) |
if (utf8) |
| 2686 |
{ |
{ |
| 2691 |
#else |
#else |
| 2692 |
othercase = NOTACHAR; |
othercase = NOTACHAR; |
| 2693 |
#endif |
#endif |
| 2694 |
return (unsigned int)item != othercase; |
return (unsigned int)c != othercase; |
| 2695 |
} |
} |
| 2696 |
else |
else |
| 2697 |
#endif /* SUPPORT_UTF8 */ |
#endif /* SUPPORT_UTF8 */ |
| 2698 |
return (item != cd->fcc[next]); /* Non-UTF-8 mode */ |
return (c != cd->fcc[next]); /* Non-UTF-8 mode */ |
| 2699 |
|
|
| 2700 |
/* For OP_NOT, "item" must be a single-byte character. */ |
/* For OP_NOT and OP_NOTI, the data is always a single-byte character. These |
| 2701 |
|
opcodes are not used for multi-byte characters, because they are coded using |
| 2702 |
|
an XCLASS instead. */ |
| 2703 |
|
|
| 2704 |
case OP_NOT: |
case OP_NOT: |
| 2705 |
if (item == next) return TRUE; |
return (c = *previous) == next; |
| 2706 |
if ((options & PCRE_CASELESS) == 0) return FALSE; |
|
| 2707 |
|
case OP_NOTI: |
| 2708 |
|
if ((c = *previous) == next) return TRUE; |
| 2709 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 2710 |
if (utf8) |
if (utf8) |
| 2711 |
{ |
{ |
| 2716 |
#else |
#else |
| 2717 |
othercase = NOTACHAR; |
othercase = NOTACHAR; |
| 2718 |
#endif |
#endif |
| 2719 |
return (unsigned int)item == othercase; |
return (unsigned int)c == othercase; |
| 2720 |
} |
} |
| 2721 |
else |
else |
| 2722 |
#endif /* SUPPORT_UTF8 */ |
#endif /* SUPPORT_UTF8 */ |
| 2723 |
return (item == cd->fcc[next]); /* Non-UTF-8 mode */ |
return (c == cd->fcc[next]); /* Non-UTF-8 mode */ |
| 2724 |
|
|
| 2725 |
|
/* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set. |
| 2726 |
|
When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */ |
| 2727 |
|
|
| 2728 |
case OP_DIGIT: |
case OP_DIGIT: |
| 2729 |
return next > 127 || (cd->ctypes[next] & ctype_digit) == 0; |
return next > 127 || (cd->ctypes[next] & ctype_digit) == 0; |
| 2766 |
case 0x202f: |
case 0x202f: |
| 2767 |
case 0x205f: |
case 0x205f: |
| 2768 |
case 0x3000: |
case 0x3000: |
| 2769 |
return op_code != OP_HSPACE; |
return op_code == OP_NOT_HSPACE; |
| 2770 |
default: |
default: |
| 2771 |
return op_code == OP_HSPACE; |
return op_code != OP_NOT_HSPACE; |
| 2772 |
} |
} |
| 2773 |
|
|
| 2774 |
|
case OP_ANYNL: |
| 2775 |
case OP_VSPACE: |
case OP_VSPACE: |
| 2776 |
case OP_NOT_VSPACE: |
case OP_NOT_VSPACE: |
| 2777 |
switch(next) |
switch(next) |
| 2783 |
case 0x85: |
case 0x85: |
| 2784 |
case 0x2028: |
case 0x2028: |
| 2785 |
case 0x2029: |
case 0x2029: |
| 2786 |
return op_code != OP_VSPACE; |
return op_code == OP_NOT_VSPACE; |
| 2787 |
default: |
default: |
| 2788 |
return op_code == OP_VSPACE; |
return op_code != OP_NOT_VSPACE; |
| 2789 |
} |
} |
| 2790 |
|
|
| 2791 |
|
#ifdef SUPPORT_UCP |
| 2792 |
|
case OP_PROP: |
| 2793 |
|
return check_char_prop(next, previous[0], previous[1], FALSE); |
| 2794 |
|
|
| 2795 |
|
case OP_NOTPROP: |
| 2796 |
|
return check_char_prop(next, previous[0], previous[1], TRUE); |
| 2797 |
|
#endif |
| 2798 |
|
|
| 2799 |
default: |
default: |
| 2800 |
return FALSE; |
return FALSE; |
| 2801 |
} |
} |
| 2802 |
|
|
| 2803 |
|
|
| 2804 |
/* Handle the case when the next item is \d, \s, etc. */ |
/* Handle the case when the next item is \d, \s, etc. Note that when PCRE_UCP |
| 2805 |
|
is set, \d turns into ESC_du rather than ESC_d, etc., so ESC_d etc. are |
| 2806 |
|
generated only when PCRE_UCP is *not* set, that is, when only ASCII |
| 2807 |
|
characteristics are recognized. Similarly, the opcodes OP_DIGIT etc. are |
| 2808 |
|
replaced by OP_PROP codes when PCRE_UCP is set. */ |
| 2809 |
|
|
| 2810 |
switch(op_code) |
switch(op_code) |
| 2811 |
{ |
{ |
| 2812 |
case OP_CHAR: |
case OP_CHAR: |
| 2813 |
case OP_CHARNC: |
case OP_CHARI: |
| 2814 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 2815 |
if (utf8 && item > 127) { GETCHAR(item, utf8_char); } |
GETCHARTEST(c, previous); |
| 2816 |
|
#else |
| 2817 |
|
c = *previous; |
| 2818 |
#endif |
#endif |
| 2819 |
switch(-next) |
switch(-next) |
| 2820 |
{ |
{ |
| 2821 |
case ESC_d: |
case ESC_d: |
| 2822 |
return item > 127 || (cd->ctypes[item] & ctype_digit) == 0; |
return c > 127 || (cd->ctypes[c] & ctype_digit) == 0; |
| 2823 |
|
|
| 2824 |
case ESC_D: |
case ESC_D: |
| 2825 |
return item <= 127 && (cd->ctypes[item] & ctype_digit) != 0; |
return c <= 127 && (cd->ctypes[c] & ctype_digit) != 0; |
| 2826 |
|
|
| 2827 |
case ESC_s: |
case ESC_s: |
| 2828 |
return item > 127 || (cd->ctypes[item] & ctype_space) == 0; |
return c > 127 || (cd->ctypes[c] & ctype_space) == 0; |
| 2829 |
|
|
| 2830 |
case ESC_S: |
case ESC_S: |
| 2831 |
return item <= 127 && (cd->ctypes[item] & ctype_space) != 0; |
return c <= 127 && (cd->ctypes[c] & ctype_space) != 0; |
| 2832 |
|
|
| 2833 |
case ESC_w: |
case ESC_w: |
| 2834 |
return item > 127 || (cd->ctypes[item] & ctype_word) == 0; |
return c > 127 || (cd->ctypes[c] & ctype_word) == 0; |
| 2835 |
|
|
| 2836 |
case ESC_W: |
case ESC_W: |
| 2837 |
return item <= 127 && (cd->ctypes[item] & ctype_word) != 0; |
return c <= 127 && (cd->ctypes[c] & ctype_word) != 0; |
| 2838 |
|
|
| 2839 |
case ESC_h: |
case ESC_h: |
| 2840 |
case ESC_H: |
case ESC_H: |
| 2841 |
switch(item) |
switch(c) |
| 2842 |
{ |
{ |
| 2843 |
case 0x09: |
case 0x09: |
| 2844 |
case 0x20: |
case 0x20: |
| 2866 |
|
|
| 2867 |
case ESC_v: |
case ESC_v: |
| 2868 |
case ESC_V: |
case ESC_V: |
| 2869 |
switch(item) |
switch(c) |
| 2870 |
{ |
{ |
| 2871 |
case 0x0a: |
case 0x0a: |
| 2872 |
case 0x0b: |
case 0x0b: |
| 2880 |
return -next == ESC_v; |
return -next == ESC_v; |
| 2881 |
} |
} |
| 2882 |
|
|
| 2883 |
|
/* When PCRE_UCP is set, these values get generated for \d etc. Find |
| 2884 |
|
their substitutions and process them. The result will always be either |
| 2885 |
|
-ESC_p or -ESC_P. Then fall through to process those values. */ |
| 2886 |
|
|
| 2887 |
|
#ifdef SUPPORT_UCP |
| 2888 |
|
case ESC_du: |
| 2889 |
|
case ESC_DU: |
| 2890 |
|
case ESC_wu: |
| 2891 |
|
case ESC_WU: |
| 2892 |
|
case ESC_su: |
| 2893 |
|
case ESC_SU: |
| 2894 |
|
{ |
| 2895 |
|
int temperrorcode = 0; |
| 2896 |
|
ptr = substitutes[-next - ESC_DU]; |
| 2897 |
|
next = check_escape(&ptr, &temperrorcode, 0, options, FALSE); |
| 2898 |
|
if (temperrorcode != 0) return FALSE; |
| 2899 |
|
ptr++; /* For compatibility */ |
| 2900 |
|
} |
| 2901 |
|
/* Fall through */ |
| 2902 |
|
|
| 2903 |
|
case ESC_p: |
| 2904 |
|
case ESC_P: |
| 2905 |
|
{ |
| 2906 |
|
int ptype, pdata, errorcodeptr; |
| 2907 |
|
BOOL negated; |
| 2908 |
|
|
| 2909 |
|
ptr--; /* Make ptr point at the p or P */ |
| 2910 |
|
ptype = get_ucp(&ptr, &negated, &pdata, &errorcodeptr); |
| 2911 |
|
if (ptype < 0) return FALSE; |
| 2912 |
|
ptr++; /* Point past the final curly ket */ |
| 2913 |
|
|
| 2914 |
|
/* If the property item is optional, we have to give up. (When generated |
| 2915 |
|
from \d etc by PCRE_UCP, this test will have been applied much earlier, |
| 2916 |
|
to the original \d etc. At this point, ptr will point to a zero byte. */ |
| 2917 |
|
|
| 2918 |
|
if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK || |
| 2919 |
|
strncmp((char *)ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0) |
| 2920 |
|
return FALSE; |
| 2921 |
|
|
| 2922 |
|
/* Do the property check. */ |
| 2923 |
|
|
| 2924 |
|
return check_char_prop(c, ptype, pdata, (next == -ESC_P) != negated); |
| 2925 |
|
} |
| 2926 |
|
#endif |
| 2927 |
|
|
| 2928 |
default: |
default: |
| 2929 |
return FALSE; |
return FALSE; |
| 2930 |
} |
} |
| 2931 |
|
|
| 2932 |
|
/* In principle, support for Unicode properties should be integrated here as |
| 2933 |
|
well. It means re-organizing the above code so as to get hold of the property |
| 2934 |
|
values before switching on the op-code. However, I wonder how many patterns |
| 2935 |
|
combine ASCII \d etc with Unicode properties? (Note that if PCRE_UCP is set, |
| 2936 |
|
these op-codes are never generated.) */ |
| 2937 |
|
|
| 2938 |
case OP_DIGIT: |
case OP_DIGIT: |
| 2939 |
return next == -ESC_D || next == -ESC_s || next == -ESC_W || |
return next == -ESC_D || next == -ESC_s || next == -ESC_W || |
| 2940 |
next == -ESC_h || next == -ESC_v; |
next == -ESC_h || next == -ESC_v || next == -ESC_R; |
| 2941 |
|
|
| 2942 |
case OP_NOT_DIGIT: |
case OP_NOT_DIGIT: |
| 2943 |
return next == -ESC_d; |
return next == -ESC_d; |
| 2944 |
|
|
| 2945 |
case OP_WHITESPACE: |
case OP_WHITESPACE: |
| 2946 |
return next == -ESC_S || next == -ESC_d || next == -ESC_w; |
return next == -ESC_S || next == -ESC_d || next == -ESC_w || next == -ESC_R; |
| 2947 |
|
|
| 2948 |
case OP_NOT_WHITESPACE: |
case OP_NOT_WHITESPACE: |
| 2949 |
return next == -ESC_s || next == -ESC_h || next == -ESC_v; |
return next == -ESC_s || next == -ESC_h || next == -ESC_v; |
| 2950 |
|
|
| 2951 |
case OP_HSPACE: |
case OP_HSPACE: |
| 2952 |
return next == -ESC_S || next == -ESC_H || next == -ESC_d || next == -ESC_w; |
return next == -ESC_S || next == -ESC_H || next == -ESC_d || |
| 2953 |
|
next == -ESC_w || next == -ESC_v || next == -ESC_R; |
| 2954 |
|
|
| 2955 |
case OP_NOT_HSPACE: |
case OP_NOT_HSPACE: |
| 2956 |
return next == -ESC_h; |
return next == -ESC_h; |
| 2957 |
|
|
| 2958 |
/* Can't have \S in here because VT matches \S (Perl anomaly) */ |
/* Can't have \S in here because VT matches \S (Perl anomaly) */ |
| 2959 |
|
case OP_ANYNL: |
| 2960 |
case OP_VSPACE: |
case OP_VSPACE: |
| 2961 |
return next == -ESC_V || next == -ESC_d || next == -ESC_w; |
return next == -ESC_V || next == -ESC_d || next == -ESC_w; |
| 2962 |
|
|
| 2963 |
case OP_NOT_VSPACE: |
case OP_NOT_VSPACE: |
| 2964 |
return next == -ESC_v; |
return next == -ESC_v || next == -ESC_R; |
| 2965 |
|
|
| 2966 |
case OP_WORDCHAR: |
case OP_WORDCHAR: |
| 2967 |
return next == -ESC_W || next == -ESC_s || next == -ESC_h || next == -ESC_v; |
return next == -ESC_W || next == -ESC_s || next == -ESC_h || |
| 2968 |
|
next == -ESC_v || next == -ESC_R; |
| 2969 |
|
|
| 2970 |
case OP_NOT_WORDCHAR: |
case OP_NOT_WORDCHAR: |
| 2971 |
return next == -ESC_w || next == -ESC_d; |
return next == -ESC_w || next == -ESC_d; |
| 3029 |
BOOL groupsetfirstbyte = FALSE; |
BOOL groupsetfirstbyte = FALSE; |
| 3030 |
const uschar *ptr = *ptrptr; |
const uschar *ptr = *ptrptr; |
| 3031 |
const uschar *tempptr; |
const uschar *tempptr; |
| 3032 |
|
const uschar *nestptr = NULL; |
| 3033 |
uschar *previous = NULL; |
uschar *previous = NULL; |
| 3034 |
uschar *previous_callout = NULL; |
uschar *previous_callout = NULL; |
| 3035 |
uschar *save_hwm = NULL; |
uschar *save_hwm = NULL; |
| 3046 |
uschar *utf8_char = NULL; |
uschar *utf8_char = NULL; |
| 3047 |
#endif |
#endif |
| 3048 |
|
|
| 3049 |
#ifdef DEBUG |
#ifdef PCRE_DEBUG |
| 3050 |
if (lengthptr != NULL) DPRINTF((">> start branch\n")); |
if (lengthptr != NULL) DPRINTF((">> start branch\n")); |
| 3051 |
#endif |
#endif |
| 3052 |
|
|
| 3100 |
|
|
| 3101 |
c = *ptr; |
c = *ptr; |
| 3102 |
|
|
| 3103 |
|
/* If we are at the end of a nested substitution, revert to the outer level |
| 3104 |
|
string. Nesting only happens one level deep. */ |
| 3105 |
|
|
| 3106 |
|
if (c == 0 && nestptr != NULL) |
| 3107 |
|
{ |
| 3108 |
|
ptr = nestptr; |
| 3109 |
|
nestptr = NULL; |
| 3110 |
|
c = *ptr; |
| 3111 |
|
} |
| 3112 |
|
|
| 3113 |
/* If we are in the pre-compile phase, accumulate the length used for the |
/* If we are in the pre-compile phase, accumulate the length used for the |
| 3114 |
previous cycle of this loop. */ |
previous cycle of this loop. */ |
| 3115 |
|
|
| 3116 |
if (lengthptr != NULL) |
if (lengthptr != NULL) |
| 3117 |
{ |
{ |
| 3118 |
#ifdef DEBUG |
#ifdef PCRE_DEBUG |
| 3119 |
if (code > cd->hwm) cd->hwm = code; /* High water info */ |
if (code > cd->hwm) cd->hwm = code; /* High water info */ |
| 3120 |
#endif |
#endif |
| 3121 |
if (code > cd->start_workspace + COMPILE_WORK_SIZE) /* Check for overrun */ |
if (code > cd->start_workspace + WORK_SIZE_CHECK) /* Check for overrun */ |
| 3122 |
{ |
{ |
| 3123 |
*errorcodeptr = ERR52; |
*errorcodeptr = ERR52; |
| 3124 |
goto FAILED; |
goto FAILED; |
| 3140 |
goto FAILED; |
goto FAILED; |
| 3141 |
} |
} |
| 3142 |
|
|
| 3143 |
*lengthptr += code - last_code; |
*lengthptr += (int)(code - last_code); |
| 3144 |
DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c)); |
DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c)); |
| 3145 |
|
|
| 3146 |
/* If "previous" is set and it is not at the start of the work space, move |
/* If "previous" is set and it is not at the start of the work space, move |
| 3167 |
/* In the real compile phase, just check the workspace used by the forward |
/* In the real compile phase, just check the workspace used by the forward |
| 3168 |
reference list. */ |
reference list. */ |
| 3169 |
|
|
| 3170 |
else if (cd->hwm > cd->start_workspace + COMPILE_WORK_SIZE) |
else if (cd->hwm > cd->start_workspace + WORK_SIZE_CHECK) |
| 3171 |
{ |
{ |
| 3172 |
*errorcodeptr = ERR52; |
*errorcodeptr = ERR52; |
| 3173 |
goto FAILED; |
goto FAILED; |
| 3222 |
if ((cd->ctypes[c] & ctype_space) != 0) continue; |
if ((cd->ctypes[c] & ctype_space) != 0) continue; |
| 3223 |
if (c == CHAR_NUMBER_SIGN) |
if (c == CHAR_NUMBER_SIGN) |
| 3224 |
{ |
{ |
| 3225 |
while (*(++ptr) != 0) |
ptr++; |
| 3226 |
|
while (*ptr != 0) |
| 3227 |
{ |
{ |
| 3228 |
if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; } |
if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; } |
| 3229 |
|
ptr++; |
| 3230 |
|
#ifdef SUPPORT_UTF8 |
| 3231 |
|
if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++; |
| 3232 |
|
#endif |
| 3233 |
} |
} |
| 3234 |
if (*ptr != 0) continue; |
if (*ptr != 0) continue; |
| 3235 |
|
|
| 3263 |
*errorcodeptr = ERR20; |
*errorcodeptr = ERR20; |
| 3264 |
goto FAILED; |
goto FAILED; |
| 3265 |
} |
} |
| 3266 |
*lengthptr += code - last_code; /* To include callout length */ |
*lengthptr += (int)(code - last_code); /* To include callout length */ |
| 3267 |
DPRINTF((">> end branch\n")); |
DPRINTF((">> end branch\n")); |
| 3268 |
} |
} |
| 3269 |
return TRUE; |
return TRUE; |
| 3274 |
the setting of any following char as a first character. */ |
the setting of any following char as a first character. */ |
| 3275 |
|
|
| 3276 |
case CHAR_CIRCUMFLEX_ACCENT: |
case CHAR_CIRCUMFLEX_ACCENT: |
| 3277 |
|
previous = NULL; |
| 3278 |
if ((options & PCRE_MULTILINE) != 0) |
if ((options & PCRE_MULTILINE) != 0) |
| 3279 |
{ |
{ |
| 3280 |
if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE; |
if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE; |
| 3281 |
|
*code++ = OP_CIRCM; |
| 3282 |
} |
} |
| 3283 |
previous = NULL; |
else *code++ = OP_CIRC; |
|
*code++ = OP_CIRC; |
|
| 3284 |
break; |
break; |
| 3285 |
|
|
| 3286 |
case CHAR_DOLLAR_SIGN: |
case CHAR_DOLLAR_SIGN: |
| 3287 |
previous = NULL; |
previous = NULL; |
| 3288 |
*code++ = OP_DOLL; |
*code++ = ((options & PCRE_MULTILINE) != 0)? OP_DOLLM : OP_DOLL; |
| 3289 |
break; |
break; |
| 3290 |
|
|
| 3291 |
/* There can never be a first char if '.' is first, whatever happens about |
/* There can never be a first char if '.' is first, whatever happens about |
| 3469 |
ptr++; |
ptr++; |
| 3470 |
} |
} |
| 3471 |
|
|
| 3472 |
posix_class = check_posix_name(ptr, tempptr - ptr); |
posix_class = check_posix_name(ptr, (int)(tempptr - ptr)); |
| 3473 |
if (posix_class < 0) |
if (posix_class < 0) |
| 3474 |
{ |
{ |
| 3475 |
*errorcodeptr = ERR30; |
*errorcodeptr = ERR30; |
| 3483 |
if ((options & PCRE_CASELESS) != 0 && posix_class <= 2) |
if ((options & PCRE_CASELESS) != 0 && posix_class <= 2) |
| 3484 |
posix_class = 0; |
posix_class = 0; |
| 3485 |
|
|
| 3486 |
/* We build the bit map for the POSIX class in a chunk of local store |
/* When PCRE_UCP is set, some of the POSIX classes are converted to |
| 3487 |
because we may be adding and subtracting from it, and we don't want to |
different escape sequences that use Unicode properties. */ |
| 3488 |
subtract bits that may be in the main map already. At the end we or the |
|
| 3489 |
result into the bit map that is being built. */ |
#ifdef SUPPORT_UCP |
| 3490 |
|
if ((options & PCRE_UCP) != 0) |
| 3491 |
|
{ |
| 3492 |
|
int pc = posix_class + ((local_negate)? POSIX_SUBSIZE/2 : 0); |
| 3493 |
|
if (posix_substitutes[pc] != NULL) |
| 3494 |
|
{ |
| 3495 |
|
nestptr = tempptr + 1; |
| 3496 |
|
ptr = posix_substitutes[pc] - 1; |
| 3497 |
|
continue; |
| 3498 |
|
} |
| 3499 |
|
} |
| 3500 |
|
#endif |
| 3501 |
|
/* In the non-UCP case, we build the bit map for the POSIX class in a |
| 3502 |
|
chunk of local store because we may be adding and subtracting from it, |
| 3503 |
|
and we don't want to subtract bits that may be in the main map already. |
| 3504 |
|
At the end we or the result into the bit map that is being built. */ |
| 3505 |
|
|
| 3506 |
posix_class *= 3; |
posix_class *= 3; |
| 3507 |
|
|
| 3545 |
|
|
| 3546 |
/* Backslash may introduce a single character, or it may introduce one |
/* Backslash may introduce a single character, or it may introduce one |
| 3547 |
of the specials, which just set a flag. The sequence \b is a special |
of the specials, which just set a flag. The sequence \b is a special |
| 3548 |
case. Inside a class (and only there) it is treated as backspace. |
case. Inside a class (and only there) it is treated as backspace. We |
| 3549 |
Elsewhere it marks a word boundary. Other escapes have preset maps ready |
assume that other escapes have more than one character in them, so set |
| 3550 |
to 'or' into the one we are building. We assume they have more than one |
class_charcount bigger than one. Unrecognized escapes fall through and |
| 3551 |
character in them, so set class_charcount bigger than one. */ |
are either treated as literal characters (by default), or are faulted if |
| 3552 |
|
PCRE_EXTRA is set. */ |
| 3553 |
|
|
| 3554 |
if (c == CHAR_BACKSLASH) |
if (c == CHAR_BACKSLASH) |
| 3555 |
{ |
{ |
| 3556 |
c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE); |
c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE); |
| 3557 |
if (*errorcodeptr != 0) goto FAILED; |
if (*errorcodeptr != 0) goto FAILED; |
| 3558 |
|
|
| 3559 |
if (-c == ESC_b) c = CHAR_BS; /* \b is backspace in a class */ |
if (-c == ESC_b) c = CHAR_BS; /* \b is backspace in a class */ |
|
else if (-c == ESC_X) c = CHAR_X; /* \X is literal X in a class */ |
|
|
else if (-c == ESC_R) c = CHAR_R; /* \R is literal R in a class */ |
|
| 3560 |
else if (-c == ESC_Q) /* Handle start of quoted string */ |
else if (-c == ESC_Q) /* Handle start of quoted string */ |
| 3561 |
{ |
{ |
| 3562 |
if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E) |
if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E) |
| 3573 |
register const uschar *cbits = cd->cbits; |
register const uschar *cbits = cd->cbits; |
| 3574 |
class_charcount += 2; /* Greater than 1 is what matters */ |
class_charcount += 2; /* Greater than 1 is what matters */ |
| 3575 |
|
|
| 3576 |
/* Save time by not doing this in the pre-compile phase. */ |
switch (-c) |
|
|
|
|
if (lengthptr == NULL) switch (-c) |
|
| 3577 |
{ |
{ |
| 3578 |
|
#ifdef SUPPORT_UCP |
| 3579 |
|
case ESC_du: /* These are the values given for \d etc */ |
| 3580 |
|
case ESC_DU: /* when PCRE_UCP is set. We replace the */ |
| 3581 |
|
case ESC_wu: /* escape sequence with an appropriate \p */ |
| 3582 |
|
case ESC_WU: /* or \P to test Unicode properties instead */ |
| 3583 |
|
case ESC_su: /* of the default ASCII testing. */ |
| 3584 |
|
case ESC_SU: |
| 3585 |
|
nestptr = ptr; |
| 3586 |
|
ptr = substitutes[-c - ESC_DU] - 1; /* Just before substitute */ |
| 3587 |
|
class_charcount -= 2; /* Undo! */ |
| 3588 |
|
continue; |
| 3589 |
|
#endif |
| 3590 |
case ESC_d: |
case ESC_d: |
| 3591 |
for (c = 0; c < 32; c++) classbits[c] |= cbits[c+cbit_digit]; |
for (c = 0; c < 32; c++) classbits[c] |= cbits[c+cbit_digit]; |
| 3592 |
continue; |
continue; |
| 3605 |
for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_word]; |
for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_word]; |
| 3606 |
continue; |
continue; |
| 3607 |
|
|
| 3608 |
|
/* Perl 5.004 onwards omits VT from \s, but we must preserve it |
| 3609 |
|
if it was previously set by something earlier in the character |
| 3610 |
|
class. */ |
| 3611 |
|
|
| 3612 |
case ESC_s: |
case ESC_s: |
| 3613 |
for (c = 0; c < 32; c++) classbits[c] |= cbits[c+cbit_space]; |
classbits[0] |= cbits[cbit_space]; |
| 3614 |
classbits[1] &= ~0x08; /* Perl 5.004 onwards omits VT from \s */ |
classbits[1] |= cbits[cbit_space+1] & ~0x08; |
| 3615 |
|
for (c = 2; c < 32; c++) classbits[c] |= cbits[c+cbit_space]; |
| 3616 |
continue; |
continue; |
| 3617 |
|
|
| 3618 |
case ESC_S: |
case ESC_S: |
| 3621 |
classbits[1] |= 0x08; /* Perl 5.004 onwards omits VT from \s */ |
classbits[1] |= 0x08; /* Perl 5.004 onwards omits VT from \s */ |
| 3622 |
continue; |
continue; |
| 3623 |
|
|
| 3624 |
default: /* Not recognized; fall through */ |
case ESC_h: |
|
break; /* Need "default" setting to stop compiler warning. */ |
|
|
} |
|
|
|
|
|
/* In the pre-compile phase, just do the recognition. */ |
|
|
|
|
|
else if (c == -ESC_d || c == -ESC_D || c == -ESC_w || |
|
|
c == -ESC_W || c == -ESC_s || c == -ESC_S) continue; |
|
|
|
|
|
/* We need to deal with \H, \h, \V, and \v in both phases because |
|
|
they use extra memory. */ |
|
|
|
|
|
if (-c == ESC_h) |
|
|
{ |
|
| 3625 |
SETBIT(classbits, 0x09); /* VT */ |
SETBIT(classbits, 0x09); /* VT */ |
| 3626 |
SETBIT(classbits, 0x20); /* SPACE */ |
SETBIT(classbits, 0x20); /* SPACE */ |
| 3627 |
SETBIT(classbits, 0xa0); /* NSBP */ |
SETBIT(classbits, 0xa0); /* NSBP */ |
| 3645 |
} |
} |
| 3646 |
#endif |
#endif |
| 3647 |
continue; |
continue; |
|
} |
|
| 3648 |
|
|
| 3649 |
if (-c == ESC_H) |
case ESC_H: |
|
{ |
|
| 3650 |
for (c = 0; c < 32; c++) |
for (c = 0; c < 32; c++) |
| 3651 |
{ |
{ |
| 3652 |
int x = 0xff; |
int x = 0xff; |
| 3688 |
} |
} |
| 3689 |
#endif |
#endif |
| 3690 |
continue; |
continue; |
|
} |
|
| 3691 |
|
|
| 3692 |
if (-c == ESC_v) |
case ESC_v: |
|
{ |
|
| 3693 |
SETBIT(classbits, 0x0a); /* LF */ |
SETBIT(classbits, 0x0a); /* LF */ |
| 3694 |
SETBIT(classbits, 0x0b); /* VT */ |
SETBIT(classbits, 0x0b); /* VT */ |
| 3695 |
SETBIT(classbits, 0x0c); /* FF */ |
SETBIT(classbits, 0x0c); /* FF */ |
| 3705 |
} |
} |
| 3706 |
#endif |
#endif |
| 3707 |
continue; |
continue; |
|
} |
|
| 3708 |
|
|
| 3709 |
if (-c == ESC_V) |
case ESC_V: |
|
{ |
|
| 3710 |
for (c = 0; c < 32; c++) |
for (c = 0; c < 32; c++) |
| 3711 |
{ |
{ |
| 3712 |
int x = 0xff; |
int x = 0xff; |
| 3736 |
} |
} |
| 3737 |
#endif |
#endif |
| 3738 |
continue; |
continue; |
|
} |
|
|
|
|
|
/* We need to deal with \P and \p in both phases. */ |
|
| 3739 |
|
|
| 3740 |
#ifdef SUPPORT_UCP |
#ifdef SUPPORT_UCP |
| 3741 |
if (-c == ESC_p || -c == ESC_P) |
case ESC_p: |
| 3742 |
{ |
case ESC_P: |
| 3743 |
BOOL negated; |
{ |
| 3744 |
int pdata; |
BOOL negated; |
| 3745 |
int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr); |
int pdata; |
| 3746 |
if (ptype < 0) goto FAILED; |
int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr); |
| 3747 |
class_utf8 = TRUE; |
if (ptype < 0) goto FAILED; |
| 3748 |
*class_utf8data++ = ((-c == ESC_p) != negated)? |
class_utf8 = TRUE; |
| 3749 |
XCL_PROP : XCL_NOTPROP; |
*class_utf8data++ = ((-c == ESC_p) != negated)? |
| 3750 |
*class_utf8data++ = ptype; |
XCL_PROP : XCL_NOTPROP; |
| 3751 |
*class_utf8data++ = pdata; |
*class_utf8data++ = ptype; |
| 3752 |
class_charcount -= 2; /* Not a < 256 character */ |
*class_utf8data++ = pdata; |
| 3753 |
continue; |
class_charcount -= 2; /* Not a < 256 character */ |
| 3754 |
} |
continue; |
| 3755 |
|
} |
| 3756 |
#endif |
#endif |
| 3757 |
/* Unrecognized escapes are faulted if PCRE is running in its |
/* Unrecognized escapes are faulted if PCRE is running in its |
| 3758 |
strict mode. By default, for compatibility with Perl, they are |
strict mode. By default, for compatibility with Perl, they are |
| 3759 |
treated as literals. */ |
treated as literals. */ |
| 3760 |
|
|
| 3761 |
if ((options & PCRE_EXTRA) != 0) |
default: |
| 3762 |
{ |
if ((options & PCRE_EXTRA) != 0) |
| 3763 |
*errorcodeptr = ERR7; |
{ |
| 3764 |
goto FAILED; |
*errorcodeptr = ERR7; |
| 3765 |
|
goto FAILED; |
| 3766 |
|
} |
| 3767 |
|
class_charcount -= 2; /* Undo the default count from above */ |
| 3768 |
|
c = *ptr; /* Get the final character and fall through */ |
| 3769 |
|
break; |
| 3770 |
} |
} |
|
|
|
|
class_charcount -= 2; /* Undo the default count from above */ |
|
|
c = *ptr; /* Get the final character and fall through */ |
|
| 3771 |
} |
} |
| 3772 |
|
|
| 3773 |
/* Fall through if we have a single character (c >= 0). This may be |
/* Fall through if we have a single character (c >= 0). This may be |
| 3837 |
d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE); |
d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE); |
| 3838 |
if (*errorcodeptr != 0) goto FAILED; |
if (*errorcodeptr != 0) goto FAILED; |
| 3839 |
|
|
| 3840 |
/* \b is backspace; \X is literal X; \R is literal R; any other |
/* \b is backspace; any other special means the '-' was literal */ |
|
special means the '-' was literal */ |
|
| 3841 |
|
|
| 3842 |
if (d < 0) |
if (d < 0) |
| 3843 |
{ |
{ |
| 3844 |
if (d == -ESC_b) d = CHAR_BS; |
if (d == -ESC_b) d = CHAR_BS; else |
|
else if (d == -ESC_X) d = CHAR_X; |
|
|
else if (d == -ESC_R) d = CHAR_R; else |
|
| 3845 |
{ |
{ |
| 3846 |
ptr = oldptr; |
ptr = oldptr; |
| 3847 |
goto LONE_SINGLE_CHARACTER; /* A few lines below */ |
goto LONE_SINGLE_CHARACTER; /* A few lines below */ |
| 4007 |
} |
} |
| 4008 |
} |
} |
| 4009 |
|
|
| 4010 |
/* Loop until ']' reached. This "while" is the end of the "do" above. */ |
/* Loop until ']' reached. This "while" is the end of the "do" far above. |
| 4011 |
|
If we are at the end of an internal nested string, revert to the outer |
| 4012 |
|
string. */ |
| 4013 |
|
|
| 4014 |
|
while (((c = *(++ptr)) != 0 || |
| 4015 |
|
(nestptr != NULL && |
| 4016 |
|
(ptr = nestptr, nestptr = NULL, c = *(++ptr)) != 0)) && |
| 4017 |
|
(c != CHAR_RIGHT_SQUARE_BRACKET || inescq)); |
| 4018 |
|
|
| 4019 |
while ((c = *(++ptr)) != 0 && (c != CHAR_RIGHT_SQUARE_BRACKET || inescq)); |
/* Check for missing terminating ']' */ |
| 4020 |
|
|
| 4021 |
if (c == 0) /* Missing terminating ']' */ |
if (c == 0) |
| 4022 |
{ |
{ |
| 4023 |
*errorcodeptr = ERR6; |
*errorcodeptr = ERR6; |
| 4024 |
goto FAILED; |
goto FAILED; |
| 4025 |
} |
} |
| 4026 |
|
|
|
|
|
|
/* This code has been disabled because it would mean that \s counts as |
|
|
an explicit \r or \n reference, and that's not really what is wanted. Now |
|
|
we set the flag only if there is a literal "\r" or "\n" in the class. */ |
|
|
|
|
|
#if 0 |
|
|
/* Remember whether \r or \n are in this class */ |
|
|
|
|
|
if (negate_class) |
|
|
{ |
|
|
if ((classbits[1] & 0x24) != 0x24) cd->external_flags |= PCRE_HASCRORLF; |
|
|
} |
|
|
else |
|
|
{ |
|
|
if ((classbits[1] & 0x24) != 0) cd->external_flags |= PCRE_HASCRORLF; |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
| 4027 |
/* If class_charcount is 1, we saw precisely one character whose value is |
/* If class_charcount is 1, we saw precisely one character whose value is |
| 4028 |
less than 256. As long as there were no characters >= 128 and there was no |
less than 256. As long as there were no characters >= 128 and there was no |
| 4029 |
use of \p or \P, in other words, no use of any XCLASS features, we can |
use of \p or \P, in other words, no use of any XCLASS features, we can |
| 4031 |
|
|
| 4032 |
In UTF-8 mode, we can optimize the negative case only if there were no |
In UTF-8 mode, we can optimize the negative case only if there were no |
| 4033 |
characters >= 128 because OP_NOT and the related opcodes like OP_NOTSTAR |
characters >= 128 because OP_NOT and the related opcodes like OP_NOTSTAR |
| 4034 |
operate on single-bytes only. This is an historical hangover. Maybe one day |
operate on single-bytes characters only. This is an historical hangover. |
| 4035 |
we can tidy these opcodes to handle multi-byte characters. |
Maybe one day we can tidy these opcodes to handle multi-byte characters. |
| 4036 |
|
|
| 4037 |
The optimization throws away the bit map. We turn the item into a |
The optimization throws away the bit map. We turn the item into a |
| 4038 |
1-character OP_CHAR[NC] if it's positive, or OP_NOT if it's negative. Note |
1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative. |
| 4039 |
that OP_NOT does not support multibyte characters. In the positive case, it |
Note that OP_NOT[I] does not support multibyte characters. In the positive |
| 4040 |
can cause firstbyte to be set. Otherwise, there can be no first char if |
case, it can cause firstbyte to be set. Otherwise, there can be no first |
| 4041 |
this item is first, whatever repeat count may follow. In the case of |
char if this item is first, whatever repeat count may follow. In the case |
| 4042 |
reqbyte, save the previous value for reinstating. */ |
of reqbyte, save the previous value for reinstating. */ |
| 4043 |
|
|
| 4044 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 4045 |
if (class_charcount == 1 && !class_utf8 && |
if (class_charcount == 1 && !class_utf8 && |
| 4050 |
{ |
{ |
| 4051 |
zeroreqbyte = reqbyte; |
zeroreqbyte = reqbyte; |
| 4052 |
|
|
| 4053 |
/* The OP_NOT opcode works on one-byte characters only. */ |
/* The OP_NOT[I] opcodes work on one-byte characters only. */ |
| 4054 |
|
|
| 4055 |
if (negate_class) |
if (negate_class) |
| 4056 |
{ |
{ |
| 4057 |
if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE; |
if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE; |
| 4058 |
zerofirstbyte = firstbyte; |
zerofirstbyte = firstbyte; |
| 4059 |
*code++ = OP_NOT; |
*code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT; |
| 4060 |
*code++ = class_lastchar; |
*code++ = class_lastchar; |
| 4061 |
break; |
break; |
| 4062 |
} |
} |
| 4087 |
|
|
| 4088 |
/* If there are characters with values > 255, we have to compile an |
/* If there are characters with values > 255, we have to compile an |
| 4089 |
extended class, with its own opcode, unless there was a negated special |
extended class, with its own opcode, unless there was a negated special |
| 4090 |
such as \S in the class, because in that case all characters > 255 are in |
such as \S in the class, and PCRE_UCP is not set, because in that case all |
| 4091 |
the class, so any that were explicitly given as well can be ignored. If |
characters > 255 are in the class, so any that were explicitly given as |
| 4092 |
(when there are explicit characters > 255 that must be listed) there are no |
well can be ignored. If (when there are explicit characters > 255 that must |
| 4093 |
characters < 256, we can omit the bitmap in the actual compiled code. */ |
be listed) there are no characters < 256, we can omit the bitmap in the |
| 4094 |
|
actual compiled code. */ |
| 4095 |
|
|
| 4096 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 4097 |
if (class_utf8 && !should_flip_negation) |
if (class_utf8 && (!should_flip_negation || (options & PCRE_UCP) != 0)) |
| 4098 |
{ |
{ |
| 4099 |
*class_utf8data++ = XCL_END; /* Marks the end of extra data */ |
*class_utf8data++ = XCL_END; /* Marks the end of extra data */ |
| 4100 |
*code++ = OP_XCLASS; |
*code++ = OP_XCLASS; |
| 4120 |
} |
} |
| 4121 |
#endif |
#endif |
| 4122 |
|
|
| 4123 |
/* If there are no characters > 255, set the opcode to OP_CLASS or |
/* If there are no characters > 255, or they are all to be included or |
| 4124 |
OP_NCLASS, depending on whether the whole class was negated and whether |
excluded, set the opcode to OP_CLASS or OP_NCLASS, depending on whether the |
| 4125 |
there were negative specials such as \S in the class. Then copy the 32-byte |
whole class was negated and whether there were negative specials such as \S |
| 4126 |
map into the code vector, negating it if necessary. */ |
(non-UCP) in the class. Then copy the 32-byte map into the code vector, |
| 4127 |
|
negating it if necessary. */ |
| 4128 |
|
|
| 4129 |
*code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS; |
*code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS; |
| 4130 |
if (negate_class) |
if (negate_class) |
| 4214 |
the first thing in a branch because the x will have gone into firstbyte |
the first thing in a branch because the x will have gone into firstbyte |
| 4215 |
instead. */ |
instead. */ |
| 4216 |
|
|
| 4217 |
if (*previous == OP_CHAR || *previous == OP_CHARNC) |
if (*previous == OP_CHAR || *previous == OP_CHARI) |
| 4218 |
{ |
{ |
| 4219 |
|
op_type = (*previous == OP_CHAR)? 0 : OP_STARI - OP_STAR; |
| 4220 |
|
|
| 4221 |
/* Deal with UTF-8 characters that take up more than one byte. It's |
/* Deal with UTF-8 characters that take up more than one byte. It's |
| 4222 |
easier to write this out separately than try to macrify it. Use c to |
easier to write this out separately than try to macrify it. Use c to |
| 4223 |
hold the length of the character in bytes, plus 0x80 to flag that it's a |
hold the length of the character in bytes, plus 0x80 to flag that it's a |
| 4250 |
|
|
| 4251 |
if (!possessive_quantifier && |
if (!possessive_quantifier && |
| 4252 |
repeat_max < 0 && |
repeat_max < 0 && |
| 4253 |
check_auto_possessive(*previous, c, utf8, utf8_char, ptr + 1, |
check_auto_possessive(previous, utf8, ptr + 1, options, cd)) |
|
options, cd)) |
|
| 4254 |
{ |
{ |
| 4255 |
repeat_type = 0; /* Force greedy */ |
repeat_type = 0; /* Force greedy */ |
| 4256 |
possessive_quantifier = TRUE; |
possessive_quantifier = TRUE; |
| 4262 |
/* If previous was a single negated character ([^a] or similar), we use |
/* If previous was a single negated character ([^a] or similar), we use |
| 4263 |
one of the special opcodes, replacing it. The code is shared with single- |
one of the special opcodes, replacing it. The code is shared with single- |
| 4264 |
character repeats by setting opt_type to add a suitable offset into |
character repeats by setting opt_type to add a suitable offset into |
| 4265 |
repeat_type. We can also test for auto-possessification. OP_NOT is |
repeat_type. We can also test for auto-possessification. OP_NOT and OP_NOTI |
| 4266 |
currently used only for single-byte chars. */ |
are currently used only for single-byte chars. */ |
| 4267 |
|
|
| 4268 |
else if (*previous == OP_NOT) |
else if (*previous == OP_NOT || *previous == OP_NOTI) |
| 4269 |
{ |
{ |
| 4270 |
op_type = OP_NOTSTAR - OP_STAR; /* Use "not" opcodes */ |
op_type = ((*previous == OP_NOT)? OP_NOTSTAR : OP_NOTSTARI) - OP_STAR; |
| 4271 |
c = previous[1]; |
c = previous[1]; |
| 4272 |
if (!possessive_quantifier && |
if (!possessive_quantifier && |
| 4273 |
repeat_max < 0 && |
repeat_max < 0 && |
| 4274 |
check_auto_possessive(OP_NOT, c, utf8, NULL, ptr + 1, options, cd)) |
check_auto_possessive(previous, utf8, ptr + 1, options, cd)) |
| 4275 |
{ |
{ |
| 4276 |
repeat_type = 0; /* Force greedy */ |
repeat_type = 0; /* Force greedy */ |
| 4277 |
possessive_quantifier = TRUE; |
possessive_quantifier = TRUE; |
| 4295 |
|
|
| 4296 |
if (!possessive_quantifier && |
if (!possessive_quantifier && |
| 4297 |
repeat_max < 0 && |
repeat_max < 0 && |
| 4298 |
check_auto_possessive(c, 0, utf8, NULL, ptr + 1, options, cd)) |
check_auto_possessive(previous, utf8, ptr + 1, options, cd)) |
| 4299 |
{ |
{ |
| 4300 |
repeat_type = 0; /* Force greedy */ |
repeat_type = 0; /* Force greedy */ |
| 4301 |
possessive_quantifier = TRUE; |
possessive_quantifier = TRUE; |
| 4317 |
|
|
| 4318 |
if (repeat_max == 0) goto END_REPEAT; |
if (repeat_max == 0) goto END_REPEAT; |
| 4319 |
|
|
| 4320 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
| 4321 |
/* This code is obsolete from release 8.00; the restriction was finally |
/* This code is obsolete from release 8.00; the restriction was finally |
| 4322 |
removed: */ |
removed: */ |
| 4323 |
|
|
| 4324 |
/* All real repeats make it impossible to handle partial matching (maybe |
/* All real repeats make it impossible to handle partial matching (maybe |
| 4325 |
one day we will be able to remove this restriction). */ |
one day we will be able to remove this restriction). */ |
| 4326 |
|
|
| 4327 |
/* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */ |
/* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */ |
| 4328 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
| 4329 |
|
|
| 4330 |
/* Combine the op_type with the repeat_type */ |
/* Combine the op_type with the repeat_type */ |
| 4331 |
|
|
| 4464 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 4465 |
*previous == OP_XCLASS || |
*previous == OP_XCLASS || |
| 4466 |
#endif |
#endif |
| 4467 |
*previous == OP_REF) |
*previous == OP_REF || |
| 4468 |
|
*previous == OP_REFI) |
| 4469 |
{ |
{ |
| 4470 |
if (repeat_max == 0) |
if (repeat_max == 0) |
| 4471 |
{ |
{ |
| 4473 |
goto END_REPEAT; |
goto END_REPEAT; |
| 4474 |
} |
} |
| 4475 |
|
|
| 4476 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
| 4477 |
/* This code is obsolete from release 8.00; the restriction was finally |
/* This code is obsolete from release 8.00; the restriction was finally |
| 4478 |
removed: */ |
removed: */ |
| 4479 |
|
|
| 4481 |
one day we will be able to remove this restriction). */ |
one day we will be able to remove this restriction). */ |
| 4482 |
|
|
| 4483 |
/* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */ |
/* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */ |
| 4484 |
/*--------------------------------------------------------------------*/ |
/*--------------------------------------------------------------------*/ |
| 4485 |
|
|
| 4486 |
if (repeat_min == 0 && repeat_max == -1) |
if (repeat_min == 0 && repeat_max == -1) |
| 4487 |
*code++ = OP_CRSTAR + repeat_type; |
*code++ = OP_CRSTAR + repeat_type; |
| 4499 |
} |
} |
| 4500 |
|
|
| 4501 |
/* If previous was a bracket group, we may have to replicate it in certain |
/* If previous was a bracket group, we may have to replicate it in certain |
| 4502 |
cases. */ |
cases. Note that at this point we can encounter only the "basic" BRA and |
| 4503 |
|
KET opcodes, as this is the place where they get converted into the more |
| 4504 |
|
special varieties. */ |
| 4505 |
|
|
| 4506 |
else if (*previous == OP_BRA || *previous == OP_CBRA || |
else if (*previous == OP_BRA || *previous == OP_CBRA || |
| 4507 |
*previous == OP_ONCE || *previous == OP_COND) |
*previous == OP_ONCE || *previous == OP_COND) |
| 4508 |
{ |
{ |
| 4509 |
register int i; |
register int i; |
| 4510 |
int ketoffset = 0; |
int len = (int)(code - previous); |
|
int len = code - previous; |
|
| 4511 |
uschar *bralink = NULL; |
uschar *bralink = NULL; |
| 4512 |
|
uschar *brazeroptr = NULL; |
| 4513 |
|
|
| 4514 |
/* Repeating a DEFINE group is pointless */ |
/* Repeating a DEFINE group is pointless */ |
| 4515 |
|
|
| 4516 |
if (*previous == OP_COND && previous[LINK_SIZE+1] == OP_DEF) |
if (*previous == OP_COND && previous[LINK_SIZE+1] == OP_DEF) |
| 4519 |
goto FAILED; |
goto FAILED; |
| 4520 |
} |
} |
| 4521 |
|
|
|
/* If the maximum repeat count is unlimited, find the end of the bracket |
|
|
by scanning through from the start, and compute the offset back to it |
|
|
from the current code pointer. There may be an OP_OPT setting following |
|
|
the final KET, so we can't find the end just by going back from the code |
|
|
pointer. */ |
|
|
|
|
|
if (repeat_max == -1) |
|
|
{ |
|
|
register uschar *ket = previous; |
|
|
do ket += GET(ket, 1); while (*ket != OP_KET); |
|
|
ketoffset = code - ket; |
|
|
} |
|
|
|
|
| 4522 |
/* The case of a zero minimum is special because of the need to stick |
/* The case of a zero minimum is special because of the need to stick |
| 4523 |
OP_BRAZERO in front of it, and because the group appears once in the |
OP_BRAZERO in front of it, and because the group appears once in the |
| 4524 |
data, whereas in other cases it appears the minimum number of times. For |
data, whereas in other cases it appears the minimum number of times. For |
| 4560 |
*previous++ = OP_SKIPZERO; |
*previous++ = OP_SKIPZERO; |
| 4561 |
goto END_REPEAT; |
goto END_REPEAT; |
| 4562 |
} |
} |
| 4563 |
|
brazeroptr = previous; /* Save for possessive optimizing */ |
| 4564 |
*previous++ = OP_BRAZERO + repeat_type; |
*previous++ = OP_BRAZERO + repeat_type; |
| 4565 |
} |
} |
| 4566 |
|
|
| 4585 |
/* We chain together the bracket offset fields that have to be |
/* We chain together the bracket offset fields that have to be |
| 4586 |
filled in later when the ends of the brackets are reached. */ |
filled in later when the ends of the brackets are reached. */ |
| 4587 |
|
|
| 4588 |
offset = (bralink == NULL)? 0 : previous - bralink; |
offset = (bralink == NULL)? 0 : (int)(previous - bralink); |
| 4589 |
bralink = previous; |
bralink = previous; |
| 4590 |
PUTINC(previous, 0, offset); |
PUTINC(previous, 0, offset); |
| 4591 |
} |
} |
| 4606 |
{ |
{ |
| 4607 |
/* In the pre-compile phase, we don't actually do the replication. We |
/* In the pre-compile phase, we don't actually do the replication. We |
| 4608 |
just adjust the length as if we had. Do some paranoid checks for |
just adjust the length as if we had. Do some paranoid checks for |
| 4609 |
potential integer overflow. */ |
potential integer overflow. The INT64_OR_DOUBLE type is a 64-bit |
| 4610 |
|
integer type when available, otherwise double. */ |
| 4611 |
|
|
| 4612 |
if (lengthptr != NULL) |
if (lengthptr != NULL) |
| 4613 |
{ |
{ |
| 4614 |
int delta = (repeat_min - 1)*length_prevgroup; |
int delta = (repeat_min - 1)*length_prevgroup; |
| 4615 |
if ((double)(repeat_min - 1)*(double)length_prevgroup > |
if ((INT64_OR_DOUBLE)(repeat_min - 1)* |
| 4616 |
(double)INT_MAX || |
(INT64_OR_DOUBLE)length_prevgroup > |
| 4617 |
|
(INT64_OR_DOUBLE)INT_MAX || |
| 4618 |
OFLOW_MAX - *lengthptr < delta) |
OFLOW_MAX - *lengthptr < delta) |
| 4619 |
{ |
{ |
| 4620 |
*errorcodeptr = ERR20; |
*errorcodeptr = ERR20; |
| 4660 |
just adjust the length as if we had. For each repetition we must add 1 |
just adjust the length as if we had. For each repetition we must add 1 |
| 4661 |
to the length for BRAZERO and for all but the last repetition we must |
to the length for BRAZERO and for all but the last repetition we must |
| 4662 |
add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some |
add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some |
| 4663 |
paranoid checks to avoid integer overflow. */ |
paranoid checks to avoid integer overflow. The INT64_OR_DOUBLE type is |
| 4664 |
|
a 64-bit integer type when available, otherwise double. */ |
| 4665 |
|
|
| 4666 |
if (lengthptr != NULL && repeat_max > 0) |
if (lengthptr != NULL && repeat_max > 0) |
| 4667 |
{ |
{ |
| 4668 |
int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) - |
int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) - |
| 4669 |
2 - 2*LINK_SIZE; /* Last one doesn't nest */ |
2 - 2*LINK_SIZE; /* Last one doesn't nest */ |
| 4670 |
if ((double)repeat_max * |
if ((INT64_OR_DOUBLE)repeat_max * |
| 4671 |
(double)(length_prevgroup + 1 + 2 + 2*LINK_SIZE) |
(INT64_OR_DOUBLE)(length_prevgroup + 1 + 2 + 2*LINK_SIZE) |
| 4672 |
> (double)INT_MAX || |
> (INT64_OR_DOUBLE)INT_MAX || |
| 4673 |
OFLOW_MAX - *lengthptr < delta) |
OFLOW_MAX - *lengthptr < delta) |
| 4674 |
{ |
{ |
| 4675 |
*errorcodeptr = ERR20; |
*errorcodeptr = ERR20; |
| 4694 |
{ |
{ |
| 4695 |
int offset; |
int offset; |
| 4696 |
*code++ = OP_BRA; |
*code++ = OP_BRA; |
| 4697 |
offset = (bralink == NULL)? 0 : code - bralink; |
offset = (bralink == NULL)? 0 : (int)(code - bralink); |
| 4698 |
bralink = code; |
bralink = code; |
| 4699 |
PUTINC(code, 0, offset); |
PUTINC(code, 0, offset); |
| 4700 |
} |
} |
| 4715 |
while (bralink != NULL) |
while (bralink != NULL) |
| 4716 |
{ |
{ |
| 4717 |
int oldlinkoffset; |
int oldlinkoffset; |
| 4718 |
int offset = code - bralink + 1; |
int offset = (int)(code - bralink + 1); |
| 4719 |
uschar *bra = code - offset; |
uschar *bra = code - offset; |
| 4720 |
oldlinkoffset = GET(bra, 1); |
oldlinkoffset = GET(bra, 1); |
| 4721 |
bralink = (oldlinkoffset == 0)? NULL : bralink - oldlinkoffset; |
bralink = (oldlinkoffset == 0)? NULL : bralink - oldlinkoffset; |
| 4725 |
} |
} |
| 4726 |
} |
} |
| 4727 |
|
|
| 4728 |
/* If the maximum is unlimited, set a repeater in the final copy. We |
/* If the maximum is unlimited, set a repeater in the final copy. For |
| 4729 |
can't just offset backwards from the current code point, because we |
ONCE brackets, that's all we need to do. |
| 4730 |
don't know if there's been an options resetting after the ket. The |
|
| 4731 |
correct offset was computed above. |
Otherwise, if the quantifier was possessive, we convert the BRA code to |
| 4732 |
|
the POS form, and the KET code to KETRPOS. (It turns out to be convenient |
| 4733 |
|
at runtime to detect this kind of subpattern at both the start and at the |
| 4734 |
|
end.) The use of special opcodes makes it possible to reduce greatly the |
| 4735 |
|
stack usage in pcre_exec(). If the group is preceded by OP_BRAZERO, |
| 4736 |
|
convert this to OP_BRAPOSZERO. Then cancel the possessive flag so that |
| 4737 |
|
the default action below, of wrapping everything inside atomic brackets, |
| 4738 |
|
does not happen. |
| 4739 |
|
|
| 4740 |
Then, when we are doing the actual compile phase, check to see whether |
Then, when we are doing the actual compile phase, check to see whether |
| 4741 |
this group is a non-atomic one that could match an empty string. If so, |
this group is one that could match an empty string. If so, convert the |
| 4742 |
convert the initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so |
initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so that runtime |
| 4743 |
that runtime checking can be done. [This check is also applied to |
checking can be done. [This check is also applied to ONCE groups at |
| 4744 |
atomic groups at runtime, but in a different way.] */ |
runtime, but in a different way.] */ |
| 4745 |
|
|
| 4746 |
else |
else |
| 4747 |
{ |
{ |
| 4748 |
uschar *ketcode = code - ketoffset; |
uschar *ketcode = code - 1 - LINK_SIZE; |
| 4749 |
uschar *bracode = ketcode - GET(ketcode, 1); |
uschar *bracode = ketcode - GET(ketcode, 1); |
| 4750 |
*ketcode = OP_KETRMAX + repeat_type; |
|
| 4751 |
if (lengthptr == NULL && *bracode != OP_ONCE) |
if (*bracode == OP_ONCE) |
| 4752 |
|
*ketcode = OP_KETRMAX + repeat_type; |
| 4753 |
|
else |
| 4754 |
{ |
{ |
| 4755 |
uschar *scode = bracode; |
if (possessive_quantifier) |
|
do |
|
| 4756 |
{ |
{ |
| 4757 |
if (could_be_empty_branch(scode, ketcode, utf8)) |
*bracode += 1; /* Switch to xxxPOS opcodes */ |
| 4758 |
|
*ketcode = OP_KETRPOS; |
| 4759 |
|
if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO; |
| 4760 |
|
possessive_quantifier = FALSE; |
| 4761 |
|
} |
| 4762 |
|
else *ketcode = OP_KETRMAX + repeat_type; |
| 4763 |
|
|
| 4764 |
|
if (lengthptr == NULL) |
| 4765 |
|
{ |
| 4766 |
|
uschar *scode = bracode; |
| 4767 |
|
do |
| 4768 |
{ |
{ |
| 4769 |
*bracode += OP_SBRA - OP_BRA; |
if (could_be_empty_branch(scode, ketcode, utf8, cd)) |
| 4770 |
break; |
{ |
| 4771 |
|
*bracode += OP_SBRA - OP_BRA; |
| 4772 |
|
break; |
| 4773 |
|
} |
| 4774 |
|
scode += GET(scode, 1); |
| 4775 |
} |
} |
| 4776 |
scode += GET(scode, 1); |
while (*scode == OP_ALT); |
| 4777 |
} |
} |
|
while (*scode == OP_ALT); |
|
| 4778 |
} |
} |
| 4779 |
} |
} |
| 4780 |
} |
} |
| 4795 |
} |
} |
| 4796 |
|
|
| 4797 |
/* If the character following a repeat is '+', or if certain optimization |
/* If the character following a repeat is '+', or if certain optimization |
| 4798 |
tests above succeeded, possessive_quantifier is TRUE. For some of the |
tests above succeeded, possessive_quantifier is TRUE. For some opcodes, |
| 4799 |
simpler opcodes, there is an special alternative opcode for this. For |
there are special alternative opcodes for this case. For anything else, we |
| 4800 |
anything else, we wrap the entire repeated item inside OP_ONCE brackets. |
wrap the entire repeated item inside OP_ONCE brackets. Logically, the '+' |
| 4801 |
The '+' notation is just syntactic sugar, taken from Sun's Java package, |
notation is just syntactic sugar, taken from Sun's Java package, but the |
| 4802 |
but the special opcodes can optimize it a bit. The repeated item starts at |
special opcodes can optimize it. |
| 4803 |
tempcode, not at previous, which might be the first part of a string whose |
|
| 4804 |
(former) last char we repeated. |
Possessively repeated subpatterns have already been handled in the code |
| 4805 |
|
just above, so possessive_quantifier is always FALSE for them at this |
| 4806 |
|
stage. |
| 4807 |
|
|
| 4808 |
|
Note that the repeated item starts at tempcode, not at previous, which |
| 4809 |
|
might be the first part of a string whose (former) last char we repeated. |
| 4810 |
|
|
| 4811 |
Possessifying an 'exact' quantifier has no effect, so we can ignore it. But |
Possessifying an 'exact' quantifier has no effect, so we can ignore it. But |
| 4812 |
an 'upto' may follow. We skip over an 'exact' item, and then test the |
an 'upto' may follow. We skip over an 'exact' item, and then test the |
| 4815 |
if (possessive_quantifier) |
if (possessive_quantifier) |
| 4816 |
{ |
{ |
| 4817 |
int len; |
int len; |
| 4818 |
|
|
| 4819 |
if (*tempcode == OP_TYPEEXACT) |
if (*tempcode == OP_TYPEEXACT) |
| 4820 |
tempcode += _pcre_OP_lengths[*tempcode] + |
tempcode += _pcre_OP_lengths[*tempcode] + |
| 4821 |
((tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP)? 2 : 0); |
((tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP)? 2 : 0); |
| 4822 |
|
|
| 4823 |
else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT) |
else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT) |
| 4824 |
{ |
{ |
| 4825 |
tempcode += _pcre_OP_lengths[*tempcode]; |
tempcode += _pcre_OP_lengths[*tempcode]; |
| 4827 |
if (utf8 && tempcode[-1] >= 0xc0) |
if (utf8 && tempcode[-1] >= 0xc0) |
| 4828 |
tempcode += _pcre_utf8_table4[tempcode[-1] & 0x3f]; |
tempcode += _pcre_utf8_table4[tempcode[-1] & 0x3f]; |
| 4829 |
#endif |
#endif |
| 4830 |
} |
} |
| 4831 |
|
|
| 4832 |
len = code - tempcode; |
len = (int)(code - tempcode); |
| 4833 |
if (len > 0) switch (*tempcode) |
if (len > 0) switch (*tempcode) |
| 4834 |
{ |
{ |
| 4835 |
case OP_STAR: *tempcode = OP_POSSTAR; break; |
case OP_STAR: *tempcode = OP_POSSTAR; break; |
| 4837 |
case OP_QUERY: *tempcode = OP_POSQUERY; break; |
case OP_QUERY: *tempcode = OP_POSQUERY; break; |
| 4838 |
case OP_UPTO: *tempcode = OP_POSUPTO; break; |
case OP_UPTO: *tempcode = OP_POSUPTO; break; |
| 4839 |
|
|
| 4840 |
case OP_TYPESTAR: *tempcode = OP_TYPEPOSSTAR; break; |
case OP_STARI: *tempcode = OP_POSSTARI; break; |
| 4841 |
case OP_TYPEPLUS: *tempcode = OP_TYPEPOSPLUS; break; |
case OP_PLUSI: *tempcode = OP_POSPLUSI; break; |
| 4842 |
case OP_TYPEQUERY: *tempcode = OP_TYPEPOSQUERY; break; |
case OP_QUERYI: *tempcode = OP_POSQUERYI; break; |
| 4843 |
case OP_TYPEUPTO: *tempcode = OP_TYPEPOSUPTO; break; |
case OP_UPTOI: *tempcode = OP_POSUPTOI; break; |
| 4844 |
|
|
| 4845 |
case OP_NOTSTAR: *tempcode = OP_NOTPOSSTAR; break; |
case OP_NOTSTAR: *tempcode = OP_NOTPOSSTAR; break; |
| 4846 |
case OP_NOTPLUS: *tempcode = OP_NOTPOSPLUS; break; |
case OP_NOTPLUS: *tempcode = OP_NOTPOSPLUS; break; |
| 4847 |
case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break; |
case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break; |
| 4848 |
case OP_NOTUPTO: *tempcode = OP_NOTPOSUPTO; break; |
case OP_NOTUPTO: *tempcode = OP_NOTPOSUPTO; break; |
| 4849 |
|
|
| 4850 |
|
case OP_NOTSTARI: *tempcode = OP_NOTPOSSTARI; break; |
| 4851 |
|
case OP_NOTPLUSI: *tempcode = OP_NOTPOSPLUSI; break; |
| 4852 |
|
case OP_NOTQUERYI: *tempcode = OP_NOTPOSQUERYI; break; |
| 4853 |
|
case OP_NOTUPTOI: *tempcode = OP_NOTPOSUPTOI; break; |
| 4854 |
|
|
| 4855 |
|
case OP_TYPESTAR: *tempcode = OP_TYPEPOSSTAR; break; |
| 4856 |
|
case OP_TYPEPLUS: *tempcode = OP_TYPEPOSPLUS; break; |
| 4857 |
|
case OP_TYPEQUERY: *tempcode = OP_TYPEPOSQUERY; break; |
| 4858 |
|
case OP_TYPEUPTO: *tempcode = OP_TYPEPOSUPTO; break; |
| 4859 |
|
|
| 4860 |
|
/* Because we are moving code along, we must ensure that any |
| 4861 |
|
pending recursive references are updated. */ |
| 4862 |
|
|
| 4863 |
default: |
default: |
| 4864 |
|
*code = OP_END; |
| 4865 |
|
adjust_recurse(tempcode, 1 + LINK_SIZE, utf8, cd, save_hwm); |
| 4866 |
memmove(tempcode + 1+LINK_SIZE, tempcode, len); |
memmove(tempcode + 1+LINK_SIZE, tempcode, len); |
| 4867 |
code += 1 + LINK_SIZE; |
code += 1 + LINK_SIZE; |
| 4868 |
len += 1 + LINK_SIZE; |
len += 1 + LINK_SIZE; |
| 4898 |
|
|
| 4899 |
/* First deal with various "verbs" that can be introduced by '*'. */ |
/* First deal with various "verbs" that can be introduced by '*'. */ |
| 4900 |
|
|
| 4901 |
if (*(++ptr) == CHAR_ASTERISK && (cd->ctypes[ptr[1]] & ctype_letter) != 0) |
if (*(++ptr) == CHAR_ASTERISK && |
| 4902 |
|
((cd->ctypes[ptr[1]] & ctype_letter) != 0 || ptr[1] == ':')) |
| 4903 |
{ |
{ |
| 4904 |
int i, namelen; |
int i, namelen; |
| 4905 |
|
int arglen = 0; |
| 4906 |
const char *vn = verbnames; |
const char *vn = verbnames; |
| 4907 |
const uschar *name = ++ptr; |
const uschar *name = ptr + 1; |
| 4908 |
|
const uschar *arg = NULL; |
| 4909 |
previous = NULL; |
previous = NULL; |
| 4910 |
while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {}; |
while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {}; |
| 4911 |
|
namelen = (int)(ptr - name); |
| 4912 |
|
|
| 4913 |
if (*ptr == CHAR_COLON) |
if (*ptr == CHAR_COLON) |
| 4914 |
{ |
{ |
| 4915 |
*errorcodeptr = ERR59; /* Not supported */ |
arg = ++ptr; |
| 4916 |
goto FAILED; |
while ((cd->ctypes[*ptr] & (ctype_letter|ctype_digit)) != 0 |
| 4917 |
|
|| *ptr == '_') ptr++; |
| 4918 |
|
arglen = (int)(ptr - arg); |
| 4919 |
} |
} |
| 4920 |
|
|
| 4921 |
if (*ptr != CHAR_RIGHT_PARENTHESIS) |
if (*ptr != CHAR_RIGHT_PARENTHESIS) |
| 4922 |
{ |
{ |
| 4923 |
*errorcodeptr = ERR60; |
*errorcodeptr = ERR60; |
| 4924 |
goto FAILED; |
goto FAILED; |
| 4925 |
} |
} |
| 4926 |
namelen = ptr - name; |
|
| 4927 |
|
/* Scan the table of verb names */ |
| 4928 |
|
|
| 4929 |
for (i = 0; i < verbcount; i++) |
for (i = 0; i < verbcount; i++) |
| 4930 |
{ |
{ |
| 4931 |
if (namelen == verbs[i].len && |
if (namelen == verbs[i].len && |
| 4932 |
strncmp((char *)name, vn, namelen) == 0) |
strncmp((char *)name, vn, namelen) == 0) |
| 4933 |
{ |
{ |
| 4934 |
/* Check for open captures before ACCEPT */ |
/* Check for open captures before ACCEPT */ |
| 4935 |
|
|
| 4936 |
if (verbs[i].op == OP_ACCEPT) |
if (verbs[i].op == OP_ACCEPT) |
| 4937 |
{ |
{ |
| 4938 |
open_capitem *oc; |
open_capitem *oc; |
| 4939 |
cd->had_accept = TRUE; |
cd->had_accept = TRUE; |
| 4940 |
for (oc = cd->open_caps; oc != NULL; oc = oc->next) |
for (oc = cd->open_caps; oc != NULL; oc = oc->next) |
| 4941 |
{ |
{ |
| 4942 |
*code++ = OP_CLOSE; |
*code++ = OP_CLOSE; |
| 4943 |
PUT2INC(code, 0, oc->number); |
PUT2INC(code, 0, oc->number); |
| 4944 |
} |
} |
| 4945 |
} |
} |
| 4946 |
*code++ = verbs[i].op; |
|
| 4947 |
break; |
/* Handle the cases with/without an argument */ |
| 4948 |
|
|
| 4949 |
|
if (arglen == 0) |
| 4950 |
|
{ |
| 4951 |
|
if (verbs[i].op < 0) /* Argument is mandatory */ |
| 4952 |
|
{ |
| 4953 |
|
*errorcodeptr = ERR66; |
| 4954 |
|
goto FAILED; |
| 4955 |
|
} |
| 4956 |
|
*code = verbs[i].op; |
| 4957 |
|
if (*code++ == OP_THEN) |
| 4958 |
|
{ |
| 4959 |
|
PUT(code, 0, code - bcptr->current_branch - 1); |
| 4960 |
|
code += LINK_SIZE; |
| 4961 |
|
} |
| 4962 |
|
} |
| 4963 |
|
|
| 4964 |
|
else |
| 4965 |
|
{ |
| 4966 |
|
if (verbs[i].op_arg < 0) /* Argument is forbidden */ |
| 4967 |
|
{ |
| 4968 |
|
*errorcodeptr = ERR59; |
| 4969 |
|
goto FAILED; |
| 4970 |
|
} |
| 4971 |
|
*code = verbs[i].op_arg; |
| 4972 |
|
if (*code++ == OP_THEN_ARG) |
| 4973 |
|
{ |
| 4974 |
|
PUT(code, 0, code - bcptr->current_branch - 1); |
| 4975 |
|
code += LINK_SIZE; |
| 4976 |
|
} |
| 4977 |
|
*code++ = arglen; |
| 4978 |
|
memcpy(code, arg, arglen); |
| 4979 |
|
code += arglen; |
| 4980 |
|
*code++ = 0; |
| 4981 |
|
} |
| 4982 |
|
|
| 4983 |
|
break; /* Found verb, exit loop */ |
| 4984 |
} |
} |
| 4985 |
|
|
| 4986 |
vn += verbs[i].len + 1; |
vn += verbs[i].len + 1; |
| 4987 |
} |
} |
| 4988 |
if (i < verbcount) continue; |
|
| 4989 |
*errorcodeptr = ERR60; |
if (i < verbcount) continue; /* Successfully handled a verb */ |
| 4990 |
|
*errorcodeptr = ERR60; /* Verb not recognized */ |
| 4991 |
goto FAILED; |
goto FAILED; |
| 4992 |
} |
} |
| 4993 |
|
|
| 5106 |
recno * 10 + *ptr - CHAR_0 : -1; |
recno * 10 + *ptr - CHAR_0 : -1; |
| 5107 |
ptr++; |
ptr++; |
| 5108 |
} |
} |
| 5109 |
namelen = ptr - name; |
namelen = (int)(ptr - name); |
| 5110 |
|
|
| 5111 |
if ((terminator > 0 && *ptr++ != terminator) || |
if ((terminator > 0 && *ptr++ != terminator) || |
| 5112 |
*ptr++ != CHAR_RIGHT_PARENTHESIS) |
*ptr++ != CHAR_RIGHT_PARENTHESIS) |
| 5143 |
} |
} |
| 5144 |
|
|
| 5145 |
/* Otherwise (did not start with "+" or "-"), start by looking for the |
/* Otherwise (did not start with "+" or "-"), start by looking for the |
| 5146 |
name. */ |
name. If we find a name, add one to the opcode to change OP_CREF or |
| 5147 |
|
OP_RREF into OP_NCREF or OP_NRREF. These behave exactly the same, |
| 5148 |
|
except they record that the reference was originally to a name. The |
| 5149 |
|
information is used to check duplicate names. */ |
| 5150 |
|
|
| 5151 |
slot = cd->name_table; |
slot = cd->name_table; |
| 5152 |
for (i = 0; i < cd->names_found; i++) |
for (i = 0; i < cd->names_found; i++) |
| 5161 |
{ |
{ |
| 5162 |
recno = GET2(slot, 0); |
recno = GET2(slot, 0); |
| 5163 |
PUT2(code, 2+LINK_SIZE, recno); |
PUT2(code, 2+LINK_SIZE, recno); |
| 5164 |
|
code[1+LINK_SIZE]++; |
| 5165 |
} |
} |
| 5166 |
|
|
| 5167 |
/* Search the pattern for a forward reference */ |
/* Search the pattern for a forward reference */ |
| 5168 |
|
|
| 5169 |
else if ((i = find_parens(cd, name, namelen, |
else if ((i = find_parens(cd, name, namelen, |
| 5170 |
(options & PCRE_EXTENDED) != 0)) > 0) |
(options & PCRE_EXTENDED) != 0, utf8)) > 0) |
| 5171 |
{ |
{ |
| 5172 |
PUT2(code, 2+LINK_SIZE, i); |
PUT2(code, 2+LINK_SIZE, i); |
| 5173 |
|
code[1+LINK_SIZE]++; |
| 5174 |
} |
} |
| 5175 |
|
|
| 5176 |
/* If terminator == 0 it means that the name followed directly after |
/* If terminator == 0 it means that the name followed directly after |
| 5302 |
goto FAILED; |
goto FAILED; |
| 5303 |
} |
} |
| 5304 |
*code++ = n; |
*code++ = n; |
| 5305 |
PUT(code, 0, ptr - cd->start_pattern + 1); /* Pattern offset */ |
PUT(code, 0, (int)(ptr - cd->start_pattern + 1)); /* Pattern offset */ |
| 5306 |
PUT(code, LINK_SIZE, 0); /* Default length */ |
PUT(code, LINK_SIZE, 0); /* Default length */ |
| 5307 |
code += 2 * LINK_SIZE; |
code += 2 * LINK_SIZE; |
| 5308 |
} |
} |
| 5309 |
previous = NULL; |
previous = NULL; |
| 5336 |
name = ++ptr; |
name = ++ptr; |
| 5337 |
|
|
| 5338 |
while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++; |
while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++; |
| 5339 |
namelen = ptr - name; |
namelen = (int)(ptr - name); |
| 5340 |
|
|
| 5341 |
/* In the pre-compile phase, just do a syntax check. */ |
/* In the pre-compile phase, just do a syntax check. */ |
| 5342 |
|
|
| 5372 |
is because the number of names, and hence the table size, is computed |
is because the number of names, and hence the table size, is computed |
| 5373 |
in the pre-compile, and it affects various numbers and pointers which |
in the pre-compile, and it affects various numbers and pointers which |
| 5374 |
would all have to be modified, and the compiled code moved down, if |
would all have to be modified, and the compiled code moved down, if |
| 5375 |
duplicates with the same number were omitted from the table. This |
duplicates with the same number were omitted from the table. This |
| 5376 |
doesn't seem worth the hassle. However, *different* names for the |
doesn't seem worth the hassle. However, *different* names for the |
| 5377 |
same number are not permitted. */ |
same number are not permitted. */ |
| 5378 |
|
|
| 5380 |
{ |
{ |
| 5381 |
BOOL dupname = FALSE; |
BOOL dupname = FALSE; |
| 5382 |
slot = cd->name_table; |
slot = cd->name_table; |
| 5383 |
|
|
| 5384 |
for (i = 0; i < cd->names_found; i++) |
for (i = 0; i < cd->names_found; i++) |
| 5385 |
{ |
{ |
| 5386 |
int crc = memcmp(name, slot+2, namelen); |
int crc = memcmp(name, slot+2, namelen); |
| 5394 |
*errorcodeptr = ERR43; |
*errorcodeptr = ERR43; |
| 5395 |
goto FAILED; |
goto FAILED; |
| 5396 |
} |
} |
| 5397 |
else dupname = TRUE; |
else dupname = TRUE; |
| 5398 |
} |
} |
| 5399 |
else crc = -1; /* Current name is a substring */ |
else crc = -1; /* Current name is a substring */ |
| 5400 |
} |
} |
| 5401 |
|
|
| 5402 |
/* Make space in the table and break the loop for an earlier |
/* Make space in the table and break the loop for an earlier |
| 5403 |
name. For a duplicate or later name, carry on. We do this for |
name. For a duplicate or later name, carry on. We do this for |
| 5404 |
duplicates so that in the simple case (when ?(| is not used) they |
duplicates so that in the simple case (when ?(| is not used) they |
| 5405 |
are in order of their numbers. */ |
are in order of their numbers. */ |
| 5406 |
|
|
| 5407 |
if (crc < 0) |
if (crc < 0) |
| 5408 |
{ |
{ |
| 5409 |
memmove(slot + cd->name_entry_size, slot, |
memmove(slot + cd->name_entry_size, slot, |
| 5410 |
(cd->names_found - i) * cd->name_entry_size); |
(cd->names_found - i) * cd->name_entry_size); |
| 5411 |
break; |
break; |
| 5412 |
} |
} |
| 5413 |
|
|
| 5414 |
/* Continue the loop for a later or duplicate name */ |
/* Continue the loop for a later or duplicate name */ |
| 5415 |
|
|
| 5416 |
slot += cd->name_entry_size; |
slot += cd->name_entry_size; |
| 5417 |
} |
} |
| 5418 |
|
|
| 5419 |
/* For non-duplicate names, check for a duplicate number before |
/* For non-duplicate names, check for a duplicate number before |
| 5420 |
adding the new name. */ |
adding the new name. */ |
| 5421 |
|
|
| 5422 |
if (!dupname) |
if (!dupname) |
| 5423 |
{ |
{ |
| 5424 |
uschar *cslot = cd->name_table; |
uschar *cslot = cd->name_table; |
| 5430 |
{ |
{ |
| 5431 |
*errorcodeptr = ERR65; |
*errorcodeptr = ERR65; |
| 5432 |
goto FAILED; |
goto FAILED; |
| 5433 |
} |
} |
| 5434 |
} |
} |
| 5435 |
else i--; |
else i--; |
| 5436 |
cslot += cd->name_entry_size; |
cslot += cd->name_entry_size; |
| 5437 |
} |
} |
| 5438 |
} |
} |
| 5439 |
|
|
| 5440 |
PUT2(slot, 0, cd->bracount + 1); |
PUT2(slot, 0, cd->bracount + 1); |
| 5441 |
memcpy(slot + 2, name, namelen); |
memcpy(slot + 2, name, namelen); |
| 5466 |
NAMED_REF_OR_RECURSE: |
NAMED_REF_OR_RECURSE: |
| 5467 |
name = ++ptr; |
name = ++ptr; |
| 5468 |
while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++; |
while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++; |
| 5469 |
namelen = ptr - name; |
namelen = (int)(ptr - name); |
| 5470 |
|
|
| 5471 |
/* In the pre-compile phase, do a syntax check and set a dummy |
/* In the pre-compile phase, do a syntax check. We used to just set |
| 5472 |
reference number. */ |
a dummy reference number, because it was not used in the first pass. |
| 5473 |
|
However, with the change of recursive back references to be atomic, |
| 5474 |
|
we have to look for the number so that this state can be identified, as |
| 5475 |
|
otherwise the incorrect length is computed. If it's not a backwards |
| 5476 |
|
reference, the dummy number will do. */ |
| 5477 |
|
|
| 5478 |
if (lengthptr != NULL) |
if (lengthptr != NULL) |
| 5479 |
{ |
{ |
| 5480 |
|
const uschar *temp; |
| 5481 |
|
|
| 5482 |
if (namelen == 0) |
if (namelen == 0) |
| 5483 |
{ |
{ |
| 5484 |
*errorcodeptr = ERR62; |
*errorcodeptr = ERR62; |
| 5494 |
*errorcodeptr = ERR48; |
*errorcodeptr = ERR48; |
| 5495 |
goto FAILED; |
goto FAILED; |
| 5496 |
} |
} |
| 5497 |
recno = 0; |
|
| 5498 |
|
/* The name table does not exist in the first pass, so we cannot |
| 5499 |
|
do a simple search as in the code below. Instead, we have to scan the |
| 5500 |
|
pattern to find the number. It is important that we scan it only as |
| 5501 |
|
far as we have got because the syntax of named subpatterns has not |
| 5502 |
|
been checked for the rest of the pattern, and find_parens() assumes |
| 5503 |
|
correct syntax. In any case, it's a waste of resources to scan |
| 5504 |
|
further. We stop the scan at the current point by temporarily |
| 5505 |
|
adjusting the value of cd->endpattern. */ |
| 5506 |
|
|
| 5507 |
|
temp = cd->end_pattern; |
| 5508 |
|
cd->end_pattern = ptr; |
| 5509 |
|
recno = find_parens(cd, name, namelen, |
| 5510 |
|
(options & PCRE_EXTENDED) != 0, utf8); |
| 5511 |
|
cd->end_pattern = temp; |
| 5512 |
|
if (recno < 0) recno = 0; /* Forward ref; set dummy number */ |
| 5513 |
} |
} |
| 5514 |
|
|
| 5515 |
/* In the real compile, seek the name in the table. We check the name |
/* In the real compile, seek the name in the table. We check the name |
| 5534 |
} |
} |
| 5535 |
else if ((recno = /* Forward back reference */ |
else if ((recno = /* Forward back reference */ |
| 5536 |
find_parens(cd, name, namelen, |
find_parens(cd, name, namelen, |
| 5537 |
(options & PCRE_EXTENDED) != 0)) <= 0) |
(options & PCRE_EXTENDED) != 0, utf8)) <= 0) |
| 5538 |
{ |
{ |
| 5539 |
*errorcodeptr = ERR15; |
*errorcodeptr = ERR15; |
| 5540 |
goto FAILED; |
goto FAILED; |
| 5637 |
if (lengthptr == NULL) |
if (lengthptr == NULL) |
| 5638 |
{ |
{ |
| 5639 |
*code = OP_END; |
*code = OP_END; |
| 5640 |
if (recno != 0) |
if (recno != 0) |
| 5641 |
called = _pcre_find_bracket(cd->start_code, utf8, recno); |
called = _pcre_find_bracket(cd->start_code, utf8, recno); |
| 5642 |
|
|
| 5643 |
/* Forward reference */ |
/* Forward reference */ |
| 5645 |
if (called == NULL) |
if (called == NULL) |
| 5646 |
{ |
{ |
| 5647 |
if (find_parens(cd, NULL, recno, |
if (find_parens(cd, NULL, recno, |
| 5648 |
(options & PCRE_EXTENDED) != 0) < 0) |
(options & PCRE_EXTENDED) != 0, utf8) < 0) |
| 5649 |
{ |
{ |
| 5650 |
*errorcodeptr = ERR15; |
*errorcodeptr = ERR15; |
| 5651 |
goto FAILED; |
goto FAILED; |
| 5652 |
} |
} |
| 5653 |
|
|
| 5654 |
|
/* Fudge the value of "called" so that when it is inserted as an |
| 5655 |
|
offset below, what it actually inserted is the reference number |
| 5656 |
|
of the group. */ |
| 5657 |
|
|
| 5658 |
called = cd->start_code + recno; |
called = cd->start_code + recno; |
| 5659 |
PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code); |
PUTINC(cd->hwm, 0, (int)(code + 2 + LINK_SIZE - cd->start_code)); |
| 5660 |
} |
} |
| 5661 |
|
|
| 5662 |
/* If not a forward reference, and the subpattern is still open, |
/* If not a forward reference, and the subpattern is still open, |
| 5664 |
recursion that could loop for ever, and diagnose that case. */ |
recursion that could loop for ever, and diagnose that case. */ |
| 5665 |
|
|
| 5666 |
else if (GET(called, 1) == 0 && |
else if (GET(called, 1) == 0 && |
| 5667 |
could_be_empty(called, code, bcptr, utf8)) |
could_be_empty(called, code, bcptr, utf8, cd)) |
| 5668 |
{ |
{ |
| 5669 |
*errorcodeptr = ERR40; |
*errorcodeptr = ERR40; |
| 5670 |
goto FAILED; |
goto FAILED; |
| 5680 |
code += 1 + LINK_SIZE; |
code += 1 + LINK_SIZE; |
| 5681 |
|
|
| 5682 |
*code = OP_RECURSE; |
*code = OP_RECURSE; |
| 5683 |
PUT(code, 1, called - cd->start_code); |
PUT(code, 1, (int)(called - cd->start_code)); |
| 5684 |
code += 1 + LINK_SIZE; |
code += 1 + LINK_SIZE; |
| 5685 |
|
|
| 5686 |
*code = OP_KET; |
*code = OP_KET; |
| 5748 |
is necessary to ensure we correctly detect the start of the pattern in |
is necessary to ensure we correctly detect the start of the pattern in |
| 5749 |
both phases. |
both phases. |
| 5750 |
|
|
| 5751 |
If we are not at the pattern start, compile code to change the ims |
If we are not at the pattern start, reset the greedy defaults and the |
| 5752 |
options if this setting actually changes any of them, and reset the |
case value for firstbyte and reqbyte. */ |
|
greedy defaults and the case value for firstbyte and reqbyte. */ |
|
| 5753 |
|
|
| 5754 |
if (*ptr == CHAR_RIGHT_PARENTHESIS) |
if (*ptr == CHAR_RIGHT_PARENTHESIS) |
| 5755 |
{ |
{ |
| 5758 |
{ |
{ |
| 5759 |
cd->external_options = newoptions; |
cd->external_options = newoptions; |
| 5760 |
} |
} |
| 5761 |
else |
else |
| 5762 |
{ |
{ |
|
if ((options & PCRE_IMS) != (newoptions & PCRE_IMS)) |
|
|
{ |
|
|
*code++ = OP_OPT; |
|
|
*code++ = newoptions & PCRE_IMS; |
|
|
} |
|
| 5763 |
greedy_default = ((newoptions & PCRE_UNGREEDY) != 0); |
greedy_default = ((newoptions & PCRE_UNGREEDY) != 0); |
| 5764 |
greedy_non_default = greedy_default ^ 1; |
greedy_non_default = greedy_default ^ 1; |
| 5765 |
req_caseopt = ((newoptions & PCRE_CASELESS) != 0)? REQ_CASELESS : 0; |
req_caseopt = ((newoptions & PCRE_CASELESS) != 0)? REQ_CASELESS : 0; |
| 5766 |
} |
} |
| 5767 |
|
|
| 5768 |
/* Change options at this level, and pass them back for use |
/* Change options at this level, and pass them back for use |
| 5769 |
in subsequent branches. When not at the start of the pattern, this |
in subsequent branches. */ |
|
information is also necessary so that a resetting item can be |
|
|
compiled at the end of a group (if we are in a group). */ |
|
| 5770 |
|
|
| 5771 |
*optionsptr = options = newoptions; |
*optionsptr = options = newoptions; |
| 5772 |
previous = NULL; /* This item can't be repeated */ |
previous = NULL; /* This item can't be repeated */ |
| 5783 |
} /* End of switch for character following (? */ |
} /* End of switch for character following (? */ |
| 5784 |
} /* End of (? handling */ |
} /* End of (? handling */ |
| 5785 |
|
|
| 5786 |
/* Opening parenthesis not followed by '?'. If PCRE_NO_AUTO_CAPTURE is set, |
/* Opening parenthesis not followed by '*' or '?'. If PCRE_NO_AUTO_CAPTURE |
| 5787 |
all unadorned brackets become non-capturing and behave like (?:...) |
is set, all unadorned brackets become non-capturing and behave like (?:...) |
| 5788 |
brackets. */ |
brackets. */ |
| 5789 |
|
|
| 5790 |
else if ((options & PCRE_NO_AUTO_CAPTURE) != 0) |
else if ((options & PCRE_NO_AUTO_CAPTURE) != 0) |
| 5804 |
|
|
| 5805 |
/* Process nested bracketed regex. Assertions may not be repeated, but |
/* Process nested bracketed regex. Assertions may not be repeated, but |
| 5806 |
other kinds can be. All their opcodes are >= OP_ONCE. We copy code into a |
other kinds can be. All their opcodes are >= OP_ONCE. We copy code into a |
| 5807 |
non-register variable in order to be able to pass its address because some |
non-register variable (tempcode) in order to be able to pass its address |
| 5808 |
compilers complain otherwise. Pass in a new setting for the ims options if |
because some compilers complain otherwise. */ |
|
they have changed. */ |
|
| 5809 |
|
|
| 5810 |
previous = (bravalue >= OP_ONCE)? code : NULL; |
previous = (bravalue >= OP_ONCE)? code : NULL; |
| 5811 |
*code = bravalue; |
*code = bravalue; |
| 5815 |
|
|
| 5816 |
if (!compile_regex( |
if (!compile_regex( |
| 5817 |
newoptions, /* The complete new option state */ |
newoptions, /* The complete new option state */ |
|
options & PCRE_IMS, /* The previous ims option state */ |
|
| 5818 |
&tempcode, /* Where to put code (updated) */ |
&tempcode, /* Where to put code (updated) */ |
| 5819 |
&ptr, /* Input pointer (updated) */ |
&ptr, /* Input pointer (updated) */ |
| 5820 |
errorcodeptr, /* Where to put an error message */ |
errorcodeptr, /* Where to put an error message */ |
| 5901 |
goto FAILED; |
goto FAILED; |
| 5902 |
} |
} |
| 5903 |
*lengthptr += length_prevgroup - 2 - 2*LINK_SIZE; |
*lengthptr += length_prevgroup - 2 - 2*LINK_SIZE; |
| 5904 |
*code++ = OP_BRA; |
code++; /* This already contains bravalue */ |
| 5905 |
PUTINC(code, 0, 1 + LINK_SIZE); |
PUTINC(code, 0, 1 + LINK_SIZE); |
| 5906 |
*code++ = OP_KET; |
*code++ = OP_KET; |
| 5907 |
PUTINC(code, 0, 1 + LINK_SIZE); |
PUTINC(code, 0, 1 + LINK_SIZE); |
| 5974 |
|
|
| 5975 |
/* ===================================================================*/ |
/* ===================================================================*/ |
| 5976 |
/* Handle metasequences introduced by \. For ones like \d, the ESC_ values |
/* Handle metasequences introduced by \. For ones like \d, the ESC_ values |
| 5977 |
are arranged to be the negation of the corresponding OP_values. For the |
are arranged to be the negation of the corresponding OP_values in the |
| 5978 |
back references, the values are ESC_REF plus the reference number. Only |
default case when PCRE_UCP is not set. For the back references, the values |
| 5979 |
back references and those types that consume a character may be repeated. |
are ESC_REF plus the reference number. Only back references and those types |
| 5980 |
We can test for values between ESC_b and ESC_Z for the latter; this may |
that consume a character may be repeated. We can test for values between |
| 5981 |
have to change if any new ones are ever created. */ |
ESC_b and ESC_Z for the latter; this may have to change if any new ones are |
| 5982 |
|
ever created. */ |
| 5983 |
|
|
| 5984 |
case CHAR_BACKSLASH: |
case CHAR_BACKSLASH: |
| 5985 |
tempptr = ptr; |
tempptr = ptr; |
| 6087 |
|
|
| 6088 |
if (-c >= ESC_REF) |
if (-c >= ESC_REF) |
| 6089 |
{ |
{ |
| 6090 |
|
open_capitem *oc; |
| 6091 |
recno = -c - ESC_REF; |
recno = -c - ESC_REF; |
| 6092 |
|
|
| 6093 |
HANDLE_REFERENCE: /* Come here from named backref handling */ |
HANDLE_REFERENCE: /* Come here from named backref handling */ |
| 6094 |
if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE; |
if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE; |
| 6095 |
previous = code; |
previous = code; |
| 6096 |
*code++ = OP_REF; |
*code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF; |
| 6097 |
PUT2INC(code, 0, recno); |
PUT2INC(code, 0, recno); |
| 6098 |
cd->backref_map |= (recno < 32)? (1 << recno) : 1; |
cd->backref_map |= (recno < 32)? (1 << recno) : 1; |
| 6099 |
if (recno > cd->top_backref) cd->top_backref = recno; |
if (recno > cd->top_backref) cd->top_backref = recno; |
| 6100 |
|
|
| 6101 |
|
/* Check to see if this back reference is recursive, that it, it |
| 6102 |
|
is inside the group that it references. A flag is set so that the |
| 6103 |
|
group can be made atomic. */ |
| 6104 |
|
|
| 6105 |
|
for (oc = cd->open_caps; oc != NULL; oc = oc->next) |
| 6106 |
|
{ |
| 6107 |
|
if (oc->number == recno) |
| 6108 |
|
{ |
| 6109 |
|
oc->flag = TRUE; |
| 6110 |
|
break; |
| 6111 |
|
} |
| 6112 |
|
} |
| 6113 |
} |
} |
| 6114 |
|
|
| 6115 |
/* So are Unicode property matches, if supported. */ |
/* So are Unicode property matches, if supported. */ |
| 6139 |
#endif |
#endif |
| 6140 |
|
|
| 6141 |
/* For the rest (including \X when Unicode properties are supported), we |
/* For the rest (including \X when Unicode properties are supported), we |
| 6142 |
can obtain the OP value by negating the escape value. */ |
can obtain the OP value by negating the escape value in the default |
| 6143 |
|
situation when PCRE_UCP is not set. When it *is* set, we substitute |
| 6144 |
|
Unicode property tests. */ |
| 6145 |
|
|
| 6146 |
else |
else |
| 6147 |
{ |
{ |
| 6148 |
previous = (-c > ESC_b && -c < ESC_Z)? code : NULL; |
#ifdef SUPPORT_UCP |
| 6149 |
*code++ = -c; |
if (-c >= ESC_DU && -c <= ESC_wu) |
| 6150 |
|
{ |
| 6151 |
|
nestptr = ptr + 1; /* Where to resume */ |
| 6152 |
|
ptr = substitutes[-c - ESC_DU] - 1; /* Just before substitute */ |
| 6153 |
|
} |
| 6154 |
|
else |
| 6155 |
|
#endif |
| 6156 |
|
{ |
| 6157 |
|
previous = (-c > ESC_b && -c < ESC_Z)? code : NULL; |
| 6158 |
|
*code++ = -c; |
| 6159 |
|
} |
| 6160 |
} |
} |
| 6161 |
continue; |
continue; |
| 6162 |
} |
} |
| 6201 |
|
|
| 6202 |
ONE_CHAR: |
ONE_CHAR: |
| 6203 |
previous = code; |
previous = code; |
| 6204 |
*code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARNC : OP_CHAR; |
*code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR; |
| 6205 |
for (c = 0; c < mclength; c++) *code++ = mcbuffer[c]; |
for (c = 0; c < mclength; c++) *code++ = mcbuffer[c]; |
| 6206 |
|
|
| 6207 |
/* Remember if \r or \n were seen */ |
/* Remember if \r or \n were seen */ |
| 6265 |
/* On entry, ptr is pointing past the bracket character, but on return it |
/* On entry, ptr is pointing past the bracket character, but on return it |
| 6266 |
points to the closing bracket, or vertical bar, or end of string. The code |
points to the closing bracket, or vertical bar, or end of string. The code |
| 6267 |
variable is pointing at the byte into which the BRA operator has been stored. |
variable is pointing at the byte into which the BRA operator has been stored. |
|
If the ims options are changed at the start (for a (?ims: group) or during any |
|
|
branch, we need to insert an OP_OPT item at the start of every following branch |
|
|
to ensure they get set correctly at run time, and also pass the new options |
|
|
into every subsequent branch compile. |
|
|
|
|
| 6268 |
This function is used during the pre-compile phase when we are trying to find |
This function is used during the pre-compile phase when we are trying to find |
| 6269 |
out the amount of memory needed, as well as during the real compile phase. The |
out the amount of memory needed, as well as during the real compile phase. The |
| 6270 |
value of lengthptr distinguishes the two phases. |
value of lengthptr distinguishes the two phases. |
| 6271 |
|
|
| 6272 |
Arguments: |
Arguments: |
| 6273 |
options option bits, including any changes for this subpattern |
options option bits, including any changes for this subpattern |
|
oldims previous settings of ims option bits |
|
| 6274 |
codeptr -> the address of the current code pointer |
codeptr -> the address of the current code pointer |
| 6275 |
ptrptr -> the address of the current pattern pointer |
ptrptr -> the address of the current pattern pointer |
| 6276 |
errorcodeptr -> pointer to error code variable |
errorcodeptr -> pointer to error code variable |
| 6288 |
*/ |
*/ |
| 6289 |
|
|
| 6290 |
static BOOL |
static BOOL |
| 6291 |
compile_regex(int options, int oldims, uschar **codeptr, const uschar **ptrptr, |
compile_regex(int options, uschar **codeptr, const uschar **ptrptr, |
| 6292 |
int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes, |
int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes, |
| 6293 |
int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr, compile_data *cd, |
int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr, compile_data *cd, |
| 6294 |
int *lengthptr) |
int *lengthptr) |
| 6308 |
branch_chain bc; |
branch_chain bc; |
| 6309 |
|
|
| 6310 |
bc.outer = bcptr; |
bc.outer = bcptr; |
| 6311 |
bc.current = code; |
bc.current_branch = code; |
| 6312 |
|
|
| 6313 |
firstbyte = reqbyte = REQ_UNSET; |
firstbyte = reqbyte = REQ_UNSET; |
| 6314 |
|
|
| 6327 |
pre-compile phase to find out whether anything has yet been compiled or not. */ |
pre-compile phase to find out whether anything has yet been compiled or not. */ |
| 6328 |
|
|
| 6329 |
/* If this is a capturing subpattern, add to the chain of open capturing items |
/* If this is a capturing subpattern, add to the chain of open capturing items |
| 6330 |
so that we can detect them if (*ACCEPT) is encountered. */ |
so that we can detect them if (*ACCEPT) is encountered. This is also used to |
| 6331 |
|
detect groups that contain recursive back references to themselves. Note that |
| 6332 |
|
only OP_CBRA need be tested here; changing this opcode to one of its variants, |
| 6333 |
|
e.g. OP_SCBRAPOS, happens later, after the group has been compiled. */ |
| 6334 |
|
|
| 6335 |
if (*code == OP_CBRA) |
if (*code == OP_CBRA) |
| 6336 |
{ |
{ |
| 6337 |
capnumber = GET2(code, 1 + LINK_SIZE); |
capnumber = GET2(code, 1 + LINK_SIZE); |
| 6338 |
capitem.number = capnumber; |
capitem.number = capnumber; |
| 6339 |
capitem.next = cd->open_caps; |
capitem.next = cd->open_caps; |
| 6340 |
cd->open_caps = &capitem; |
capitem.flag = FALSE; |
| 6341 |
} |
cd->open_caps = &capitem; |
| 6342 |
|
} |
| 6343 |
|
|
| 6344 |
/* Offset is set zero to mark that this bracket is still open */ |
/* Offset is set zero to mark that this bracket is still open */ |
| 6345 |
|
|
| 6356 |
|
|
| 6357 |
if (reset_bracount) cd->bracount = orig_bracount; |
if (reset_bracount) cd->bracount = orig_bracount; |
| 6358 |
|
|
|
/* Handle a change of ims options at the start of the branch */ |
|
|
|
|
|
if ((options & PCRE_IMS) != oldims) |
|
|
{ |
|
|
*code++ = OP_OPT; |
|
|
*code++ = options & PCRE_IMS; |
|
|
length += 2; |
|
|
} |
|
|
|
|
| 6359 |
/* Set up dummy OP_REVERSE if lookbehind assertion */ |
/* Set up dummy OP_REVERSE if lookbehind assertion */ |
| 6360 |
|
|
| 6361 |
if (lookbehind) |
if (lookbehind) |
| 6426 |
|
|
| 6427 |
/* If lookbehind, check that this branch matches a fixed-length string, and |
/* If lookbehind, check that this branch matches a fixed-length string, and |
| 6428 |
put the length into the OP_REVERSE item. Temporarily mark the end of the |
put the length into the OP_REVERSE item. Temporarily mark the end of the |
| 6429 |
branch with OP_END. If the branch contains OP_RECURSE, the result is -3 |
branch with OP_END. If the branch contains OP_RECURSE, the result is -3 |
| 6430 |
because there may be forward references that we can't check here. Set a |
because there may be forward references that we can't check here. Set a |
| 6431 |
flag to cause another lookbehind check at the end. Why not do it all at the |
flag to cause another lookbehind check at the end. Why not do it all at the |
| 6432 |
end? Because common, erroneous checks are picked up here and the offset of |
end? Because common, erroneous checks are picked up here and the offset of |
| 6433 |
the problem can be shown. */ |
the problem can be shown. */ |
| 6434 |
|
|
| 6435 |
if (lookbehind) |
if (lookbehind) |
| 6436 |
{ |
{ |
| 6437 |
int fixed_length; |
int fixed_length; |
| 6438 |
*code = OP_END; |
*code = OP_END; |
| 6439 |
fixed_length = find_fixedlength(last_branch, options, FALSE, cd); |
fixed_length = find_fixedlength(last_branch, (options & PCRE_UTF8) != 0, |
| 6440 |
|
FALSE, cd); |
| 6441 |
DPRINTF(("fixed length = %d\n", fixed_length)); |
DPRINTF(("fixed length = %d\n", fixed_length)); |
| 6442 |
if (fixed_length == -3) |
if (fixed_length == -3) |
| 6443 |
{ |
{ |
| 6444 |
cd->check_lookbehind = TRUE; |
cd->check_lookbehind = TRUE; |
| 6445 |
} |
} |
| 6446 |
else if (fixed_length < 0) |
else if (fixed_length < 0) |
| 6447 |
{ |
{ |
| 6448 |
*errorcodeptr = (fixed_length == -2)? ERR36 : ERR25; |
*errorcodeptr = (fixed_length == -2)? ERR36 : ERR25; |
| 6458 |
of offsets, with the field in the BRA item now becoming an offset to the |
of offsets, with the field in the BRA item now becoming an offset to the |
| 6459 |
first alternative. If there are no alternatives, it points to the end of the |
first alternative. If there are no alternatives, it points to the end of the |
| 6460 |
group. The length in the terminating ket is always the length of the whole |
group. The length in the terminating ket is always the length of the whole |
| 6461 |
bracketed item. If any of the ims options were changed inside the group, |
bracketed item. Return leaving the pointer at the terminating char. */ |
|
compile a resetting op-code following, except at the very end of the pattern. |
|
|
Return leaving the pointer at the terminating char. */ |
|
| 6462 |
|
|
| 6463 |
if (*ptr != CHAR_VERTICAL_LINE) |
if (*ptr != CHAR_VERTICAL_LINE) |
| 6464 |
{ |
{ |
| 6465 |
if (lengthptr == NULL) |
if (lengthptr == NULL) |
| 6466 |
{ |
{ |
| 6467 |
int branch_length = code - last_branch; |
int branch_length = (int)(code - last_branch); |
| 6468 |
do |
do |
| 6469 |
{ |
{ |
| 6470 |
int prev_length = GET(last_branch, 1); |
int prev_length = GET(last_branch, 1); |
| 6474 |
} |
} |
| 6475 |
while (branch_length > 0); |
while (branch_length > 0); |
| 6476 |
} |
} |
|
|
|
|
/* If it was a capturing subpattern, remove it from the chain. */ |
|
|
|
|
|
if (capnumber > 0) cd->open_caps = cd->open_caps->next; |
|
| 6477 |
|
|
| 6478 |
/* Fill in the ket */ |
/* Fill in the ket */ |
| 6479 |
|
|
| 6480 |
*code = OP_KET; |
*code = OP_KET; |
| 6481 |
PUT(code, 1, code - start_bracket); |
PUT(code, 1, (int)(code - start_bracket)); |
| 6482 |
code += 1 + LINK_SIZE; |
code += 1 + LINK_SIZE; |
| 6483 |
|
|
| 6484 |
/* Resetting option if needed */ |
/* If it was a capturing subpattern, check to see if it contained any |
| 6485 |
|
recursive back references. If so, we must wrap it in atomic brackets. |
| 6486 |
|
In any event, remove the block from the chain. */ |
| 6487 |
|
|
| 6488 |
if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS) |
if (capnumber > 0) |
| 6489 |
{ |
{ |
| 6490 |
*code++ = OP_OPT; |
if (cd->open_caps->flag) |
| 6491 |
*code++ = oldims; |
{ |
| 6492 |
length += 2; |
memmove(start_bracket + 1 + LINK_SIZE, start_bracket, |
| 6493 |
|
code - start_bracket); |
| 6494 |
|
*start_bracket = OP_ONCE; |
| 6495 |
|
code += 1 + LINK_SIZE; |
| 6496 |
|
PUT(start_bracket, 1, (int)(code - start_bracket)); |
| 6497 |
|
*code = OP_KET; |
| 6498 |
|
PUT(code, 1, (int)(code - start_bracket)); |
| 6499 |
|
code += 1 + LINK_SIZE; |
| 6500 |
|
length += 2 + 2*LINK_SIZE; |
| 6501 |
|
} |
| 6502 |
|
cd->open_caps = cd->open_caps->next; |
| 6503 |
} |
} |
| 6504 |
|
|
| 6505 |
/* Retain the highest bracket number, in case resetting was used. */ |
/* Retain the highest bracket number, in case resetting was used. */ |
| 6541 |
else |
else |
| 6542 |
{ |
{ |
| 6543 |
*code = OP_ALT; |
*code = OP_ALT; |
| 6544 |
PUT(code, 1, code - last_branch); |
PUT(code, 1, (int)(code - last_branch)); |
| 6545 |
bc.current = last_branch = code; |
bc.current_branch = last_branch = code; |
| 6546 |
code += 1 + LINK_SIZE; |
code += 1 + LINK_SIZE; |
| 6547 |
} |
} |
| 6548 |
|
|
| 6561 |
/* Try to find out if this is an anchored regular expression. Consider each |
/* Try to find out if this is an anchored regular expression. Consider each |
| 6562 |
alternative branch. If they all start with OP_SOD or OP_CIRC, or with a bracket |
alternative branch. If they all start with OP_SOD or OP_CIRC, or with a bracket |
| 6563 |
all of whose alternatives start with OP_SOD or OP_CIRC (recurse ad lib), then |
all of whose alternatives start with OP_SOD or OP_CIRC (recurse ad lib), then |
| 6564 |
it's anchored. However, if this is a multiline pattern, then only OP_SOD |
it's anchored. However, if this is a multiline pattern, then only OP_SOD will |
| 6565 |
counts, since OP_CIRC can match in the middle. |
be found, because ^ generates OP_CIRCM in that mode. |
| 6566 |
|
|
| 6567 |
We can also consider a regex to be anchored if OP_SOM starts all its branches. |
We can also consider a regex to be anchored if OP_SOM starts all its branches. |
| 6568 |
This is the code for \G, which means "match at start of match position, taking |
This is the code for \G, which means "match at start of match position, taking |
| 6583 |
|
|
| 6584 |
Arguments: |
Arguments: |
| 6585 |
code points to start of expression (the bracket) |
code points to start of expression (the bracket) |
|
options points to the options setting |
|
| 6586 |
bracket_map a bitmap of which brackets we are inside while testing; this |
bracket_map a bitmap of which brackets we are inside while testing; this |
| 6587 |
handles up to substring 31; after that we just have to take |
handles up to substring 31; after that we just have to take |
| 6588 |
the less precise approach |
the less precise approach |
| 6592 |
*/ |
*/ |
| 6593 |
|
|
| 6594 |
static BOOL |
static BOOL |
| 6595 |
is_anchored(register const uschar *code, int *options, unsigned int bracket_map, |
is_anchored(register const uschar *code, unsigned int bracket_map, |
| 6596 |
unsigned int backref_map) |
unsigned int backref_map) |
| 6597 |
{ |
{ |
| 6598 |
do { |
do { |
| 6599 |
const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code], |
const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code], |
| 6600 |
options, PCRE_MULTILINE, FALSE); |
FALSE); |
| 6601 |
register int op = *scode; |
register int op = *scode; |
| 6602 |
|
|
| 6603 |
/* Non-capturing brackets */ |
/* Non-capturing brackets */ |
| 6604 |
|
|
| 6605 |
if (op == OP_BRA) |
if (op == OP_BRA || op == OP_BRAPOS || |
| 6606 |
|
op == OP_SBRA || op == OP_SBRAPOS) |
| 6607 |
{ |
{ |
| 6608 |
if (!is_anchored(scode, options, bracket_map, backref_map)) return FALSE; |
if (!is_anchored(scode, bracket_map, backref_map)) return FALSE; |
| 6609 |
} |
} |
| 6610 |
|
|
| 6611 |
/* Capturing brackets */ |
/* Capturing brackets */ |
| 6612 |
|
|
| 6613 |
else if (op == OP_CBRA) |
else if (op == OP_CBRA || op == OP_CBRAPOS || |
| 6614 |
|
op == OP_SCBRA || op == OP_SCBRAPOS) |
| 6615 |
{ |
{ |
| 6616 |
int n = GET2(scode, 1+LINK_SIZE); |
int n = GET2(scode, 1+LINK_SIZE); |
| 6617 |
int new_map = bracket_map | ((n < 32)? (1 << n) : 1); |
int new_map = bracket_map | ((n < 32)? (1 << n) : 1); |
| 6618 |
if (!is_anchored(scode, options, new_map, backref_map)) return FALSE; |
if (!is_anchored(scode, new_map, backref_map)) return FALSE; |
| 6619 |
} |
} |
| 6620 |
|
|
| 6621 |
/* Other brackets */ |
/* Other brackets */ |
| 6622 |
|
|
| 6623 |
else if (op == OP_ASSERT || op == OP_ONCE || op == OP_COND) |
else if (op == OP_ASSERT || op == OP_ONCE || op == OP_COND) |
| 6624 |
{ |
{ |
| 6625 |
if (!is_anchored(scode, options, bracket_map, backref_map)) return FALSE; |
if (!is_anchored(scode, bracket_map, backref_map)) return FALSE; |
| 6626 |
} |
} |
| 6627 |
|
|
| 6628 |
/* .* is not anchored unless DOTALL is set (which generates OP_ALLANY) and |
/* .* is not anchored unless DOTALL is set (which generates OP_ALLANY) and |
| 6637 |
|
|
| 6638 |
/* Check for explicit anchoring */ |
/* Check for explicit anchoring */ |
| 6639 |
|
|
| 6640 |
else if (op != OP_SOD && op != OP_SOM && |
else if (op != OP_SOD && op != OP_SOM && op != OP_CIRC) return FALSE; |
|
((*options & PCRE_MULTILINE) != 0 || op != OP_CIRC)) |
|
|
return FALSE; |
|
| 6641 |
code += GET(code, 1); |
code += GET(code, 1); |
| 6642 |
} |
} |
| 6643 |
while (*code == OP_ALT); /* Loop for each alternative */ |
while (*code == OP_ALT); /* Loop for each alternative */ |
| 6673 |
{ |
{ |
| 6674 |
do { |
do { |
| 6675 |
const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code], |
const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code], |
| 6676 |
NULL, 0, FALSE); |
FALSE); |
| 6677 |
register int op = *scode; |
register int op = *scode; |
| 6678 |
|
|
| 6679 |
/* If we are at the start of a conditional assertion group, *both* the |
/* If we are at the start of a conditional assertion group, *both* the |
| 6688 |
switch (*scode) |
switch (*scode) |
| 6689 |
{ |
{ |
| 6690 |
case OP_CREF: |
case OP_CREF: |
| 6691 |
|
case OP_NCREF: |
| 6692 |
case OP_RREF: |
case OP_RREF: |
| 6693 |
|
case OP_NRREF: |
| 6694 |
case OP_DEF: |
case OP_DEF: |
| 6695 |
return FALSE; |
return FALSE; |
| 6696 |
|
|
| 6700 |
scode += 1 + LINK_SIZE; |
scode += 1 + LINK_SIZE; |
| 6701 |
break; |
break; |
| 6702 |
} |
} |
| 6703 |
scode = first_significant_code(scode, NULL, 0, FALSE); |
scode = first_significant_code(scode, FALSE); |
| 6704 |
op = *scode; |
op = *scode; |
| 6705 |
} |
} |
| 6706 |
|
|
| 6707 |
/* Non-capturing brackets */ |
/* Non-capturing brackets */ |
| 6708 |
|
|
| 6709 |
if (op == OP_BRA) |
if (op == OP_BRA || op == OP_BRAPOS || |
| 6710 |
|
op == OP_SBRA || op == OP_SBRAPOS) |
| 6711 |
{ |
{ |
| 6712 |
if (!is_startline(scode, bracket_map, backref_map)) return FALSE; |
if (!is_startline(scode, bracket_map, backref_map)) return FALSE; |
| 6713 |
} |
} |
| 6714 |
|
|
| 6715 |
/* Capturing brackets */ |
/* Capturing brackets */ |
| 6716 |
|
|
| 6717 |
else if (op == OP_CBRA) |
else if (op == OP_CBRA || op == OP_CBRAPOS || |
| 6718 |
|
op == OP_SCBRA || op == OP_SCBRAPOS) |
| 6719 |
{ |
{ |
| 6720 |
int n = GET2(scode, 1+LINK_SIZE); |
int n = GET2(scode, 1+LINK_SIZE); |
| 6721 |
int new_map = bracket_map | ((n < 32)? (1 << n) : 1); |
int new_map = bracket_map | ((n < 32)? (1 << n) : 1); |
| 6739 |
|
|
| 6740 |
/* Check for explicit circumflex */ |
/* Check for explicit circumflex */ |
| 6741 |
|
|
| 6742 |
else if (op != OP_CIRC) return FALSE; |
else if (op != OP_CIRC && op != OP_CIRCM) return FALSE; |
| 6743 |
|
|
| 6744 |
/* Move on to the next alternative */ |
/* Move on to the next alternative */ |
| 6745 |
|
|
| 6765 |
|
|
| 6766 |
Arguments: |
Arguments: |
| 6767 |
code points to start of expression (the bracket) |
code points to start of expression (the bracket) |
|
options pointer to the options (used to check casing changes) |
|
| 6768 |
inassert TRUE if in an assertion |
inassert TRUE if in an assertion |
| 6769 |
|
|
| 6770 |
Returns: -1 or the fixed first char |
Returns: -1 or the fixed first char |
| 6771 |
*/ |
*/ |
| 6772 |
|
|
| 6773 |
static int |
static int |
| 6774 |
find_firstassertedchar(const uschar *code, int *options, BOOL inassert) |
find_firstassertedchar(const uschar *code, BOOL inassert) |
| 6775 |
{ |
{ |
| 6776 |
register int c = -1; |
register int c = -1; |
| 6777 |
do { |
do { |
| 6778 |
int d; |
int d; |
| 6779 |
const uschar *scode = |
int xl = (*code == OP_CBRA || *code == OP_SCBRA || |
| 6780 |
first_significant_code(code + 1+LINK_SIZE, options, PCRE_CASELESS, TRUE); |
*code == OP_CBRAPOS || *code == OP_SCBRAPOS)? 2:0; |
| 6781 |
|
const uschar *scode = first_significant_code(code + 1+LINK_SIZE + xl, TRUE); |
| 6782 |
register int op = *scode; |
register int op = *scode; |
| 6783 |
|
|
| 6784 |
switch(op) |
switch(op) |
| 6787 |
return -1; |
return -1; |
| 6788 |
|
|
| 6789 |
case OP_BRA: |
case OP_BRA: |
| 6790 |
|
case OP_BRAPOS: |
| 6791 |
case OP_CBRA: |
case OP_CBRA: |
| 6792 |
|
case OP_SCBRA: |
| 6793 |
|
case OP_CBRAPOS: |
| 6794 |
|
case OP_SCBRAPOS: |
| 6795 |
case OP_ASSERT: |
case OP_ASSERT: |
| 6796 |
case OP_ONCE: |
case OP_ONCE: |
| 6797 |
case OP_COND: |
case OP_COND: |
| 6798 |
if ((d = find_firstassertedchar(scode, options, op == OP_ASSERT)) < 0) |
if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0) |
| 6799 |
return -1; |
return -1; |
| 6800 |
if (c < 0) c = d; else if (c != d) return -1; |
if (c < 0) c = d; else if (c != d) return -1; |
| 6801 |
break; |
break; |
| 6802 |
|
|
| 6803 |
case OP_EXACT: /* Fall through */ |
case OP_EXACT: |
| 6804 |
scode += 2; |
scode += 2; |
| 6805 |
|
/* Fall through */ |
| 6806 |
|
|
| 6807 |
case OP_CHAR: |
case OP_CHAR: |
|
case OP_CHARNC: |
|
| 6808 |
case OP_PLUS: |
case OP_PLUS: |
| 6809 |
case OP_MINPLUS: |
case OP_MINPLUS: |
| 6810 |
case OP_POSPLUS: |
case OP_POSPLUS: |
| 6811 |
if (!inassert) return -1; |
if (!inassert) return -1; |
| 6812 |
if (c < 0) |
if (c < 0) c = scode[1]; |
| 6813 |
{ |
else if (c != scode[1]) return -1; |
| 6814 |
c = scode[1]; |
break; |
| 6815 |
if ((*options & PCRE_CASELESS) != 0) c |= REQ_CASELESS; |
|
| 6816 |
} |
case OP_EXACTI: |
| 6817 |
else if (c != scode[1]) return -1; |
scode += 2; |
| 6818 |
|
/* Fall through */ |
| 6819 |
|
|
| 6820 |
|
case OP_CHARI: |
| 6821 |
|
case OP_PLUSI: |
| 6822 |
|
case OP_MINPLUSI: |
| 6823 |
|
case OP_POSPLUSI: |
| 6824 |
|
if (!inassert) return -1; |
| 6825 |
|
if (c < 0) c = scode[1] | REQ_CASELESS; |
| 6826 |
|
else if (c != scode[1]) return -1; |
| 6827 |
break; |
break; |
| 6828 |
} |
} |
| 6829 |
|
|
| 6874 |
int firstbyte, reqbyte, newline; |
int firstbyte, reqbyte, newline; |
| 6875 |
int errorcode = 0; |
int errorcode = 0; |
| 6876 |
int skipatstart = 0; |
int skipatstart = 0; |
| 6877 |
BOOL utf8 = (options & PCRE_UTF8) != 0; |
BOOL utf8; |
| 6878 |
size_t size; |
size_t size; |
| 6879 |
uschar *code; |
uschar *code; |
| 6880 |
const uschar *codestart; |
const uschar *codestart; |
| 6944 |
|
|
| 6945 |
if (strncmp((char *)(ptr+skipatstart+2), STRING_UTF8_RIGHTPAR, 5) == 0) |
if (strncmp((char *)(ptr+skipatstart+2), STRING_UTF8_RIGHTPAR, 5) == 0) |
| 6946 |
{ skipatstart += 7; options |= PCRE_UTF8; continue; } |
{ skipatstart += 7; options |= PCRE_UTF8; continue; } |
| 6947 |
|
else if (strncmp((char *)(ptr+skipatstart+2), STRING_UCP_RIGHTPAR, 4) == 0) |
| 6948 |
|
{ skipatstart += 6; options |= PCRE_UCP; continue; } |
| 6949 |
|
else if (strncmp((char *)(ptr+skipatstart+2), STRING_NO_START_OPT_RIGHTPAR, 13) == 0) |
| 6950 |
|
{ skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; } |
| 6951 |
|
|
| 6952 |
if (strncmp((char *)(ptr+skipatstart+2), STRING_CR_RIGHTPAR, 3) == 0) |
if (strncmp((char *)(ptr+skipatstart+2), STRING_CR_RIGHTPAR, 3) == 0) |
| 6953 |
{ skipatstart += 5; newnl = PCRE_NEWLINE_CR; } |
{ skipatstart += 5; newnl = PCRE_NEWLINE_CR; } |
| 6972 |
else break; |
else break; |
| 6973 |
} |
} |
| 6974 |
|
|
| 6975 |
/* Can't support UTF8 unless PCRE has been compiled to include the code. */ |
utf8 = (options & PCRE_UTF8) != 0; |
| 6976 |
|
|
| 6977 |
|
/* Can't support UTF8 unless PCRE has been compiled to include the code. The |
| 6978 |
|
return of an error code from _pcre_valid_utf8() is a new feature, introduced in |
| 6979 |
|
release 8.13. The only use we make of it here is to adjust the offset value to |
| 6980 |
|
the end of the string for a short string error, for compatibility with previous |
| 6981 |
|
versions. */ |
| 6982 |
|
|
| 6983 |
#ifdef SUPPORT_UTF8 |
#ifdef SUPPORT_UTF8 |
| 6984 |
if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 && |
if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 && |
| 6985 |
(*erroroffset = _pcre_valid_utf8((uschar *)pattern, -1)) >= 0) |
(*erroroffset = _pcre_valid_utf8((USPTR)pattern, -1, &errorcode)) >= 0) |
| 6986 |
{ |
{ |
| 6987 |
errorcode = ERR44; |
errorcode = ERR44; |
| 6988 |
goto PCRE_EARLY_ERROR_RETURN2; |
goto PCRE_EARLY_ERROR_RETURN2; |
| 6995 |
} |
} |
| 6996 |
#endif |
#endif |
| 6997 |
|
|
| 6998 |
|
/* Can't support UCP unless PCRE has been compiled to include the code. */ |
| 6999 |
|
|
| 7000 |
|
#ifndef SUPPORT_UCP |
| 7001 |
|
if ((options & PCRE_UCP) != 0) |
| 7002 |
|
{ |
| 7003 |
|
errorcode = ERR67; |
| 7004 |
|
goto PCRE_EARLY_ERROR_RETURN; |
| 7005 |
|
} |
| 7006 |
|
#endif |
| 7007 |
|
|
| 7008 |
/* Check validity of \R options. */ |
/* Check validity of \R options. */ |
| 7009 |
|
|
| 7010 |
switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) |
switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) |
| 7098 |
ptr += skipatstart; |
ptr += skipatstart; |
| 7099 |
code = cworkspace; |
code = cworkspace; |
| 7100 |
*code = OP_BRA; |
*code = OP_BRA; |
| 7101 |
(void)compile_regex(cd->external_options, cd->external_options & PCRE_IMS, |
(void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE, |
| 7102 |
&code, &ptr, &errorcode, FALSE, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, |
FALSE, 0, &firstbyte, &reqbyte, NULL, cd, &length); |
|
&length); |
|
| 7103 |
if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN; |
if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN; |
| 7104 |
|
|
| 7105 |
DPRINTF(("end pre-compile: length=%d workspace=%d\n", length, |
DPRINTF(("end pre-compile: length=%d workspace=%d\n", length, |
| 7132 |
pointers. */ |
pointers. */ |
| 7133 |
|
|
| 7134 |
re->magic_number = MAGIC_NUMBER; |
re->magic_number = MAGIC_NUMBER; |
| 7135 |
re->size = size; |
re->size = (int)size; |
| 7136 |
re->options = cd->external_options; |
re->options = cd->external_options; |
| 7137 |
re->flags = cd->external_flags; |
re->flags = cd->external_flags; |
| 7138 |
re->dummy1 = 0; |
re->dummy1 = 0; |
| 7171 |
ptr = (const uschar *)pattern + skipatstart; |
ptr = (const uschar *)pattern + skipatstart; |
| 7172 |
code = (uschar *)codestart; |
code = (uschar *)codestart; |
| 7173 |
*code = OP_BRA; |
*code = OP_BRA; |
| 7174 |
(void)compile_regex(re->options, re->options & PCRE_IMS, &code, &ptr, |
(void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, |
| 7175 |
&errorcode, FALSE, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, NULL); |
&firstbyte, &reqbyte, NULL, cd, NULL); |
| 7176 |
re->top_bracket = cd->bracount; |
re->top_bracket = cd->bracount; |
| 7177 |
re->top_backref = cd->top_backref; |
re->top_backref = cd->top_backref; |
| 7178 |
re->flags = cd->external_flags; |
re->flags = cd->external_flags; |
| 7188 |
|
|
| 7189 |
*code++ = OP_END; |
*code++ = OP_END; |
| 7190 |
|
|
| 7191 |
#ifndef DEBUG |
#ifndef PCRE_DEBUG |
| 7192 |
if (code - codestart > length) errorcode = ERR23; |
if (code - codestart > length) errorcode = ERR23; |
| 7193 |
#endif |
#endif |
| 7194 |
|
|
| 7203 |
recno = GET(codestart, offset); |
recno = GET(codestart, offset); |
| 7204 |
groupptr = _pcre_find_bracket(codestart, utf8, recno); |
groupptr = _pcre_find_bracket(codestart, utf8, recno); |
| 7205 |
if (groupptr == NULL) errorcode = ERR53; |
if (groupptr == NULL) errorcode = ERR53; |
| 7206 |
else PUT(((uschar *)codestart), offset, groupptr - codestart); |
else PUT(((uschar *)codestart), offset, (int)(groupptr - codestart)); |
| 7207 |
} |
} |
| 7208 |
|
|
| 7209 |
/* Give an error if there's back reference to a non-existent capturing |
/* Give an error if there's back reference to a non-existent capturing |
| 7211 |
|
|
| 7212 |
if (errorcode == 0 && re->top_backref > re->top_bracket) errorcode = ERR15; |
if (errorcode == 0 && re->top_backref > re->top_bracket) errorcode = ERR15; |
| 7213 |
|
|
| 7214 |
/* If there were any lookbehind assertions that contained OP_RECURSE |
/* If there were any lookbehind assertions that contained OP_RECURSE |
| 7215 |
(recursions or subroutine calls), a flag is set for them to be checked here, |
(recursions or subroutine calls), a flag is set for them to be checked here, |
| 7216 |
because they may contain forward references. Actual recursions can't be fixed |
because they may contain forward references. Actual recursions can't be fixed |
| 7217 |
length, but subroutine calls can. It is done like this so that those without |
length, but subroutine calls can. It is done like this so that those without |
| 7222 |
if (cd->check_lookbehind) |
if (cd->check_lookbehind) |
| 7223 |
{ |
{ |
| 7224 |
uschar *cc = (uschar *)codestart; |
uschar *cc = (uschar *)codestart; |
| 7225 |
|
|
| 7226 |
/* Loop, searching for OP_REVERSE items, and process those that do not have |
/* Loop, searching for OP_REVERSE items, and process those that do not have |
| 7227 |
their length set. (Actually, it will also re-process any that have a length |
their length set. (Actually, it will also re-process any that have a length |
| 7228 |
of zero, but that is a pathological case, and it does no harm.) When we find |
of zero, but that is a pathological case, and it does no harm.) When we find |
| 7229 |
one, we temporarily terminate the branch it is in while we scan it. */ |
one, we temporarily terminate the branch it is in while we scan it. */ |
| 7230 |
|
|
| 7231 |
for (cc = (uschar *)_pcre_find_bracket(codestart, utf8, -1); |
for (cc = (uschar *)_pcre_find_bracket(codestart, utf8, -1); |
| 7232 |
cc != NULL; |
cc != NULL; |
| 7233 |
cc = (uschar *)_pcre_find_bracket(cc, utf8, -1)) |
cc = (uschar *)_pcre_find_bracket(cc, utf8, -1)) |
| 7234 |
{ |
{ |
| 7235 |
if (GET(cc, 1) == 0) |
if (GET(cc, 1) == 0) |
| 7236 |
{ |
{ |
| 7237 |
int fixed_length; |
int fixed_length; |
| 7238 |
uschar *be = cc - 1 - LINK_SIZE + GET(cc, -LINK_SIZE); |
uschar *be = cc - 1 - LINK_SIZE + GET(cc, -LINK_SIZE); |
| 7239 |
int end_op = *be; |
int end_op = *be; |
| 7240 |
*be = OP_END; |
*be = OP_END; |
| 7241 |
fixed_length = find_fixedlength(cc, re->options, TRUE, cd); |
fixed_length = find_fixedlength(cc, (re->options & PCRE_UTF8) != 0, TRUE, |
| 7242 |
|
cd); |
| 7243 |
*be = end_op; |
*be = end_op; |
| 7244 |
DPRINTF(("fixed length = %d\n", fixed_length)); |
DPRINTF(("fixed length = %d\n", fixed_length)); |
| 7245 |
if (fixed_length < 0) |
if (fixed_length < 0) |
| 7246 |
{ |
{ |
| 7247 |
errorcode = (fixed_length == -2)? ERR36 : ERR25; |
errorcode = (fixed_length == -2)? ERR36 : ERR25; |
| 7248 |
break; |
break; |
| 7249 |
} |
} |
| 7250 |
PUT(cc, 1, fixed_length); |
PUT(cc, 1, fixed_length); |
| 7251 |
} |
} |
| 7252 |
cc += 1 + LINK_SIZE; |
cc += 1 + LINK_SIZE; |
| 7253 |
} |
} |
| 7254 |
} |
} |
| 7255 |
|
|
| 7256 |
/* Failed to compile, or error while post-processing */ |
/* Failed to compile, or error while post-processing */ |
| 7257 |
|
|
| 7259 |
{ |
{ |
| 7260 |
(pcre_free)(re); |
(pcre_free)(re); |
| 7261 |
PCRE_EARLY_ERROR_RETURN: |
PCRE_EARLY_ERROR_RETURN: |
| 7262 |
*erroroffset = ptr - (const uschar *)pattern; |
*erroroffset = (int)(ptr - (const uschar *)pattern); |
| 7263 |
PCRE_EARLY_ERROR_RETURN2: |
PCRE_EARLY_ERROR_RETURN2: |
| 7264 |
*errorptr = find_error_text(errorcode); |
*errorptr = find_error_text(errorcode); |
| 7265 |
if (errorcodeptr != NULL) *errorcodeptr = errorcode; |
if (errorcodeptr != NULL) *errorcodeptr = errorcode; |
| 7278 |
|
|
| 7279 |
if ((re->options & PCRE_ANCHORED) == 0) |
if ((re->options & PCRE_ANCHORED) == 0) |
| 7280 |
{ |
{ |
| 7281 |
int temp_options = re->options; /* May get changed during these scans */ |
if (is_anchored(codestart, 0, cd->backref_map)) |
|
if (is_anchored(codestart, &temp_options, 0, cd->backref_map)) |
|
| 7282 |
re->options |= PCRE_ANCHORED; |
re->options |= PCRE_ANCHORED; |
| 7283 |
else |
else |
| 7284 |
{ |
{ |
| 7285 |
if (firstbyte < 0) |
if (firstbyte < 0) |
| 7286 |
firstbyte = find_firstassertedchar(codestart, &temp_options, FALSE); |
firstbyte = find_firstassertedchar(codestart, FALSE); |
| 7287 |
if (firstbyte >= 0) /* Remove caseless flag for non-caseable chars */ |
if (firstbyte >= 0) /* Remove caseless flag for non-caseable chars */ |
| 7288 |
{ |
{ |
| 7289 |
int ch = firstbyte & 255; |
int ch = firstbyte & 255; |
| 7312 |
/* Print out the compiled data if debugging is enabled. This is never the |
/* Print out the compiled data if debugging is enabled. This is never the |
| 7313 |
case when building a production library. */ |
case when building a production library. */ |
| 7314 |
|
|
| 7315 |
#ifdef DEBUG |
#ifdef PCRE_DEBUG |
|
|
|
| 7316 |
printf("Length = %d top_bracket = %d top_backref = %d\n", |
printf("Length = %d top_bracket = %d top_backref = %d\n", |
| 7317 |
length, re->top_bracket, re->top_backref); |
length, re->top_bracket, re->top_backref); |
| 7318 |
|
|
| 7349 |
if (errorcodeptr != NULL) *errorcodeptr = ERR23; |
if (errorcodeptr != NULL) *errorcodeptr = ERR23; |
| 7350 |
return NULL; |
return NULL; |
| 7351 |
} |
} |
| 7352 |
#endif /* DEBUG */ |
#endif /* PCRE_DEBUG */ |
| 7353 |
|
|
| 7354 |
return (pcre *)re; |
return (pcre *)re; |
| 7355 |
} |
} |