/[pcre]/code/trunk/pcre_compile.c
ViewVC logotype

Diff of /code/trunk/pcre_compile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 395 by ph10, Fri Mar 20 11:22:42 2009 UTC revision 512 by ph10, Tue Mar 30 11:11:52 2010 UTC
# Line 6  Line 6 
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-2010 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
# Line 53  supporting internal functions that are n Line 53  supporting internal functions that are n
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    
# Line 91  is 4 there is plenty of room. */ Line 92  is 4 there is plenty of room. */
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
# Line 182  string is built from string macros so th Line 188  string is built from string macros so th
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
# Line 196  static const char verbnames[] = Line 205  static const char verbnames[] =
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);
# Line 262  the number of relocations needed when a Line 273  the number of relocations needed when a
273  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
274  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
275  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
276  because these strings are used only when there is a compilation error. */  because these strings are used only when there is a compilation error.
277    
278    Each substring ends with \0 to insert a null character. This includes the final
279    substring, so that the whole string ends with \0\0, which can be detected when
280    counting through. */
281    
282  static const char error_texts[] =  static const char error_texts[] =
283    "no error\0"    "no error\0"
# Line 335  static const char error_texts[] = Line 350  static const char error_texts[] =
350    "inconsistent NEWLINE options\0"    "inconsistent NEWLINE options\0"
351    "\\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"
352    "a numbered reference must not be zero\0"    "a numbered reference must not be zero\0"
353    "(*VERB) with an argument is not supported\0"    "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"
354    /* 60 */    /* 60 */
355    "(*VERB) not recognized\0"    "(*VERB) not recognized\0"
356    "number is too big\0"    "number is too big\0"
357    "subpattern name expected\0"    "subpattern name expected\0"
358    "digit expected after (?+\0"    "digit expected after (?+\0"
359    "] is an invalid data character in JavaScript compatibility mode";    "] is an invalid data character in JavaScript compatibility mode\0"
360      /* 65 */
361      "different names for subpatterns of the same number are not allowed\0"
362      "(*MARK) must have an argument\0"
363      ;
364    
365  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
366  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
# Line 500  static const char * Line 518  static const char *
518  find_error_text(int n)  find_error_text(int n)
519  {  {
520  const char *s = error_texts;  const char *s = error_texts;
521  for (; n > 0; n--) while (*s++ != 0) {};  for (; n > 0; n--)
522      {
523      while (*s++ != 0) {};
524      if (*s == 0) return "Error text not found (please report)";
525      }
526  return s;  return s;
527  }  }
528    
# Line 1009  return p; Line 1031  return p;
1031    
1032    
1033  /*************************************************  /*************************************************
1034  *       Find forward referenced subpattern       *  *  Subroutine for finding forward reference      *
1035  *************************************************/  *************************************************/
1036    
1037  /* This function scans along a pattern's text looking for capturing  /* This recursive function is called only from find_parens() below. The
1038    top-level call starts at the beginning of the pattern. All other calls must
1039    start at a parenthesis. It scans along a pattern's text looking for capturing
1040  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
1041  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
1042  returns when it reaches a given numbered subpattern. This is used for forward  returns when it reaches a given numbered subpattern. We know that if (?P< is
1043  references to subpatterns. We know that if (?P< is encountered, the name will  encountered, the name will be terminated by '>' because that is checked in the
1044  be terminated by '>' because that is checked in the first pass.  first pass. Recursion is used to keep track of subpatterns that reset the
1045    capturing group numbers - the (?| feature.
1046    
1047  Arguments:  Arguments:
1048    ptr          current position in the pattern    ptrptr       address of the current character pointer (updated)
1049    cd           compile background data    cd           compile background data
1050    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1051    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1052    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1053      count        pointer to the current capturing subpattern number (updated)
1054    
1055  Returns:       the number of the named subpattern, or -1 if not found  Returns:       the number of the named subpattern, or -1 if not found
1056  */  */
1057    
1058  static int  static int
1059  find_parens(const uschar *ptr, compile_data *cd, const uschar *name, int lorn,  find_parens_sub(uschar **ptrptr, compile_data *cd, const uschar *name, int lorn,
1060    BOOL xmode)    BOOL xmode, int *count)
1061  {  {
1062  const uschar *thisname;  uschar *ptr = *ptrptr;
1063  int count = cd->bracount;  int start_count = *count;
1064    int hwm_count = start_count;
1065    BOOL dup_parens = FALSE;
1066    
1067  for (; *ptr != 0; ptr++)  /* If the first character is a parenthesis, check on the type of group we are
1068    dealing with. The very first call may not start with a parenthesis. */
1069    
1070    if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1071    {    {
1072    int term;    if (ptr[1] == CHAR_QUESTION_MARK &&
1073          ptr[2] == CHAR_VERTICAL_LINE)
1074        {
1075        ptr += 3;
1076        dup_parens = TRUE;
1077        }
1078    
1079      /* Handle a normal, unnamed capturing parenthesis */
1080    
1081      else if (ptr[1] != CHAR_QUESTION_MARK && ptr[1] != CHAR_ASTERISK)
1082        {
1083        *count += 1;
1084        if (name == NULL && *count == lorn) return *count;
1085        ptr++;
1086        }
1087    
1088      /* Handle a condition. If it is an assertion, just carry on so that it
1089      is processed as normal. If not, skip to the closing parenthesis of the
1090      condition (there can't be any nested parens. */
1091    
1092      else if (ptr[2] == CHAR_LEFT_PARENTHESIS)
1093        {
1094        ptr += 2;
1095        if (ptr[1] != CHAR_QUESTION_MARK)
1096          {
1097          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
1098          if (*ptr != 0) ptr++;
1099          }
1100        }
1101    
1102      /* We have either (? or (* and not a condition */
1103    
1104      else
1105        {
1106        ptr += 2;
1107        if (*ptr == CHAR_P) ptr++;                      /* Allow optional P */
1108    
1109        /* We have to disambiguate (?<! and (?<= from (?<name> for named groups */
1110    
1111        if ((*ptr == CHAR_LESS_THAN_SIGN && ptr[1] != CHAR_EXCLAMATION_MARK &&
1112            ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)
1113          {
1114          int term;
1115          const uschar *thisname;
1116          *count += 1;
1117          if (name == NULL && *count == lorn) return *count;
1118          term = *ptr++;
1119          if (term == CHAR_LESS_THAN_SIGN) term = CHAR_GREATER_THAN_SIGN;
1120          thisname = ptr;
1121          while (*ptr != term) ptr++;
1122          if (name != NULL && lorn == ptr - thisname &&
1123              strncmp((const char *)name, (const char *)thisname, lorn) == 0)
1124            return *count;
1125          term++;
1126          }
1127        }
1128      }
1129    
1130    /* Past any initial parenthesis handling, scan for parentheses or vertical
1131    bars. */
1132    
1133    for (; *ptr != 0; ptr++)
1134      {
1135    /* Skip over backslashed characters and also entire \Q...\E */    /* Skip over backslashed characters and also entire \Q...\E */
1136    
1137    if (*ptr == CHAR_BACKSLASH)    if (*ptr == CHAR_BACKSLASH)
1138      {      {
1139      if (*(++ptr) == 0) return -1;      if (*(++ptr) == 0) goto FAIL_EXIT;
1140      if (*ptr == CHAR_Q) for (;;)      if (*ptr == CHAR_Q) for (;;)
1141        {        {
1142        while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};        while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};
1143        if (*ptr == 0) return -1;        if (*ptr == 0) goto FAIL_EXIT;
1144        if (*(++ptr) == CHAR_E) break;        if (*(++ptr) == CHAR_E) break;
1145        }        }
1146      continue;      continue;
# Line 1065  for (; *ptr != 0; ptr++) Line 1157  for (; *ptr != 0; ptr++)
1157      BOOL negate_class = FALSE;      BOOL negate_class = FALSE;
1158      for (;;)      for (;;)
1159        {        {
1160        int c = *(++ptr);        if (ptr[1] == CHAR_BACKSLASH)
       if (c == CHAR_BACKSLASH)  
1161          {          {
1162          if (ptr[1] == CHAR_E)          if (ptr[2] == CHAR_E)
1163            ptr++;            ptr+= 2;
1164          else if (strncmp((const char *)ptr+1,          else if (strncmp((const char *)ptr+2,
1165                   STR_Q STR_BACKSLASH STR_E, 3) == 0)                   STR_Q STR_BACKSLASH STR_E, 3) == 0)
1166            ptr += 3;            ptr += 4;
1167          else          else
1168            break;            break;
1169          }          }
1170        else if (!negate_class && c == CHAR_CIRCUMFLEX_ACCENT)        else if (!negate_class && ptr[1] == CHAR_CIRCUMFLEX_ACCENT)
1171            {
1172          negate_class = TRUE;          negate_class = TRUE;
1173            ptr++;
1174            }
1175        else break;        else break;
1176        }        }
1177    
# Line 1093  for (; *ptr != 0; ptr++) Line 1187  for (; *ptr != 0; ptr++)
1187        if (*ptr == 0) return -1;        if (*ptr == 0) return -1;
1188        if (*ptr == CHAR_BACKSLASH)        if (*ptr == CHAR_BACKSLASH)
1189          {          {
1190          if (*(++ptr) == 0) return -1;          if (*(++ptr) == 0) goto FAIL_EXIT;
1191          if (*ptr == CHAR_Q) for (;;)          if (*ptr == CHAR_Q) for (;;)
1192            {            {
1193            while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};            while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};
1194            if (*ptr == 0) return -1;            if (*ptr == 0) goto FAIL_EXIT;
1195            if (*(++ptr) == CHAR_E) break;            if (*(++ptr) == CHAR_E) break;
1196            }            }
1197          continue;          continue;
# Line 1111  for (; *ptr != 0; ptr++) Line 1205  for (; *ptr != 0; ptr++)
1205    if (xmode && *ptr == CHAR_NUMBER_SIGN)    if (xmode && *ptr == CHAR_NUMBER_SIGN)
1206      {      {
1207      while (*(++ptr) != 0 && *ptr != CHAR_NL) {};      while (*(++ptr) != 0 && *ptr != CHAR_NL) {};
1208      if (*ptr == 0) return -1;      if (*ptr == 0) goto FAIL_EXIT;
1209      continue;      continue;
1210      }      }
1211    
1212    /* An opening parens must now be a real metacharacter */    /* Check for the special metacharacters */
1213    
1214    if (*ptr != CHAR_LEFT_PARENTHESIS) continue;    if (*ptr == CHAR_LEFT_PARENTHESIS)
   if (ptr[1] != CHAR_QUESTION_MARK && ptr[1] != CHAR_ASTERISK)  
1215      {      {
1216      count++;      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, count);
1217      if (name == NULL && count == lorn) return count;      if (rc > 0) return rc;
1218      continue;      if (*ptr == 0) goto FAIL_EXIT;
1219        }
1220    
1221      else if (*ptr == CHAR_RIGHT_PARENTHESIS)
1222        {
1223        if (dup_parens && *count < hwm_count) *count = hwm_count;
1224        *ptrptr = ptr;
1225        return -1;
1226      }      }
1227    
1228    ptr += 2;    else if (*ptr == CHAR_VERTICAL_LINE && dup_parens)
1229    if (*ptr == CHAR_P) ptr++;                      /* Allow optional P */      {
1230        if (*count > hwm_count) hwm_count = *count;
1231        *count = start_count;
1232        }
1233      }
1234    
1235    FAIL_EXIT:
1236    *ptrptr = ptr;
1237    return -1;
1238    }
1239    
   /* We have to disambiguate (?<! and (?<= from (?<name> */  
1240    
   if ((*ptr != CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_EXCLAMATION_MARK ||  
       ptr[1] == CHAR_EQUALS_SIGN) && *ptr != CHAR_APOSTROPHE)  
     continue;  
1241    
   count++;  
1242    
1243    if (name == NULL && count == lorn) return count;  /*************************************************
1244    term = *ptr++;  *       Find forward referenced subpattern       *
1245    if (term == CHAR_LESS_THAN_SIGN) term = CHAR_GREATER_THAN_SIGN;  *************************************************/
1246    thisname = ptr;  
1247    while (*ptr != term) ptr++;  /* This function scans along a pattern's text looking for capturing
1248    if (name != NULL && lorn == ptr - thisname &&  subpatterns, and counting them. If it finds a named pattern that matches the
1249        strncmp((const char *)name, (const char *)thisname, lorn) == 0)  name it is given, it returns its number. Alternatively, if the name is NULL, it
1250      return count;  returns when it reaches a given numbered subpattern. This is used for forward
1251    references to subpatterns. We used to be able to start this scan from the
1252    current compiling point, using the current count value from cd->bracount, and
1253    do it all in a single loop, but the addition of the possibility of duplicate
1254    subpattern numbers means that we have to scan from the very start, in order to
1255    take account of such duplicates, and to use a recursive function to keep track
1256    of the different types of group.
1257    
1258    Arguments:
1259      cd           compile background data
1260      name         name to seek, or NULL if seeking a numbered subpattern
1261      lorn         name length, or subpattern number if name is NULL
1262      xmode        TRUE if we are in /x mode
1263    
1264    Returns:       the number of the found subpattern, or -1 if not found
1265    */
1266    
1267    static int
1268    find_parens(compile_data *cd, const uschar *name, int lorn, BOOL xmode)
1269    {
1270    uschar *ptr = (uschar *)cd->start_pattern;
1271    int count = 0;
1272    int rc;
1273    
1274    /* If the pattern does not start with an opening parenthesis, the first call
1275    to find_parens_sub() will scan right to the end (if necessary). However, if it
1276    does start with a parenthesis, find_parens_sub() will return when it hits the
1277    matching closing parens. That is why we have to have a loop. */
1278    
1279    for (;;)
1280      {
1281      rc = find_parens_sub(&ptr, cd, name, lorn, xmode, &count);
1282      if (rc > 0 || *ptr++ == 0) break;
1283    }    }
1284    
1285  return -1;  return rc;
1286  }  }
1287    
1288    
1289    
1290    
1291  /*************************************************  /*************************************************
1292  *      Find first significant op code            *  *      Find first significant op code            *
1293  *************************************************/  *************************************************/
# Line 1200  for (;;) Line 1337  for (;;)
1337    
1338      case OP_CALLOUT:      case OP_CALLOUT:
1339      case OP_CREF:      case OP_CREF:
1340        case OP_NCREF:
1341      case OP_RREF:      case OP_RREF:
1342        case OP_NRREF:
1343      case OP_DEF:      case OP_DEF:
1344      code += _pcre_OP_lengths[*code];      code += _pcre_OP_lengths[*code];
1345      break;      break;
# Line 1216  for (;;) Line 1355  for (;;)
1355    
1356    
1357  /*************************************************  /*************************************************
1358  *        Find the fixed length of a pattern      *  *        Find the fixed length of a branch       *
1359  *************************************************/  *************************************************/
1360    
1361  /* Scan a pattern 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,
1362  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.
1363  In UTF8 mode, the result is in characters rather than bytes.  In UTF8 mode, the result is in characters rather than bytes. The branch is
1364    temporarily terminated with OP_END when this function is called.
1365    
1366    This function is called when a backward assertion is encountered, so that if it
1367    fails, the error message can point to the correct place in the pattern.
1368    However, we cannot do this when the assertion contains subroutine calls,
1369    because they can be forward references. We solve this by remembering this case
1370    and doing the check at the end; a flag specifies which mode we are running in.
1371    
1372  Arguments:  Arguments:
1373    code     points to the start of the pattern (the bracket)    code     points to the start of the pattern (the bracket)
1374    options  the compiling options    options  the compiling options
1375      atend    TRUE if called when the pattern is complete
1376      cd       the "compile data" structure
1377    
1378  Returns:   the fixed length, or -1 if there is no fixed length,  Returns:   the fixed length,
1379                 or -1 if there is no fixed length,
1380               or -2 if \C was encountered               or -2 if \C was encountered
1381                 or -3 if an OP_RECURSE item was encountered and atend is FALSE
1382  */  */
1383    
1384  static int  static int
1385  find_fixedlength(uschar *code, int options)  find_fixedlength(uschar *code, int options, BOOL atend, compile_data *cd)
1386  {  {
1387  int length = -1;  int length = -1;
1388    
# Line 1245  branch, check the length against that of Line 1395  branch, check the length against that of
1395  for (;;)  for (;;)
1396    {    {
1397    int d;    int d;
1398      uschar *ce, *cs;
1399    register int op = *cc;    register int op = *cc;
1400    switch (op)    switch (op)
1401      {      {
# Line 1252  for (;;) Line 1403  for (;;)
1403      case OP_BRA:      case OP_BRA:
1404      case OP_ONCE:      case OP_ONCE:
1405      case OP_COND:      case OP_COND:
1406      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), options);      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), options, atend, cd);
1407      if (d < 0) return d;      if (d < 0) return d;
1408      branchlength += d;      branchlength += d;
1409      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 1275  for (;;) Line 1426  for (;;)
1426      branchlength = 0;      branchlength = 0;
1427      break;      break;
1428    
1429        /* A true recursion implies not fixed length, but a subroutine call may
1430        be OK. If the subroutine is a forward reference, we can't deal with
1431        it until the end of the pattern, so return -3. */
1432    
1433        case OP_RECURSE:
1434        if (!atend) return -3;
1435        cs = ce = (uschar *)cd->start_code + GET(cc, 1);  /* Start subpattern */
1436        do ce += GET(ce, 1); while (*ce == OP_ALT);       /* End subpattern */
1437        if (cc > cs && cc < ce) return -1;                /* Recursion */
1438        d = find_fixedlength(cs + 2, options, atend, cd);
1439        if (d < 0) return d;
1440        branchlength += d;
1441        cc += 1 + LINK_SIZE;
1442        break;
1443    
1444      /* Skip over assertive subpatterns */      /* Skip over assertive subpatterns */
1445    
1446      case OP_ASSERT:      case OP_ASSERT:
# Line 1288  for (;;) Line 1454  for (;;)
1454    
1455      case OP_REVERSE:      case OP_REVERSE:
1456      case OP_CREF:      case OP_CREF:
1457        case OP_NCREF:
1458      case OP_RREF:      case OP_RREF:
1459        case OP_NRREF:
1460      case OP_DEF:      case OP_DEF:
1461      case OP_OPT:      case OP_OPT:
1462      case OP_CALLOUT:      case OP_CALLOUT:
1463      case OP_SOD:      case OP_SOD:
1464      case OP_SOM:      case OP_SOM:
1465        case OP_SET_SOM:
1466      case OP_EOD:      case OP_EOD:
1467      case OP_EODN:      case OP_EODN:
1468      case OP_CIRC:      case OP_CIRC:
# Line 1311  for (;;) Line 1480  for (;;)
1480      branchlength++;      branchlength++;
1481      cc += 2;      cc += 2;
1482  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1483      if ((options & PCRE_UTF8) != 0)      if ((options & PCRE_UTF8) != 0 && cc[-1] >= 0xc0)
1484        {        cc += _pcre_utf8_table4[cc[-1] & 0x3f];
       while ((*cc & 0xc0) == 0x80) cc++;  
       }  
1485  #endif  #endif
1486      break;      break;
1487    
# Line 1325  for (;;) Line 1492  for (;;)
1492      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1493      cc += 4;      cc += 4;
1494  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1495      if ((options & PCRE_UTF8) != 0)      if ((options & PCRE_UTF8) != 0 && cc[-1] >= 0xc0)
1496        {        cc += _pcre_utf8_table4[cc[-1] & 0x3f];
       while((*cc & 0x80) == 0x80) cc++;  
       }  
1497  #endif  #endif
1498      break;      break;
1499    
# Line 1407  for (;;) Line 1572  for (;;)
1572    
1573    
1574  /*************************************************  /*************************************************
1575  *    Scan compiled regex for numbered bracket    *  *    Scan compiled regex for specific bracket    *
1576  *************************************************/  *************************************************/
1577    
1578  /* This little function scans through a compiled pattern until it finds a  /* This little function scans through a compiled pattern until it finds a
1579  capturing bracket with the given number.  capturing bracket with the given number, or, if the number is negative, an
1580    instance of OP_REVERSE for a lookbehind. The function is global in the C sense
1581    so that it can be called from pcre_study() when finding the minimum matching
1582    length.
1583    
1584  Arguments:  Arguments:
1585    code        points to start of expression    code        points to start of expression
1586    utf8        TRUE in UTF-8 mode    utf8        TRUE in UTF-8 mode
1587    number      the required bracket number    number      the required bracket number or negative to find a lookbehind
1588    
1589  Returns:      pointer to the opcode for the bracket, or NULL if not found  Returns:      pointer to the opcode for the bracket, or NULL if not found
1590  */  */
1591    
1592  static const uschar *  const uschar *
1593  find_bracket(const uschar *code, BOOL utf8, int number)  _pcre_find_bracket(const uschar *code, BOOL utf8, int number)
1594  {  {
1595  for (;;)  for (;;)
1596    {    {
# Line 1435  for (;;) Line 1603  for (;;)
1603    
1604    if (c == OP_XCLASS) code += GET(code, 1);    if (c == OP_XCLASS) code += GET(code, 1);
1605    
1606      /* Handle recursion */
1607    
1608      else if (c == OP_REVERSE)
1609        {
1610        if (number < 0) return (uschar *)code;
1611        code += _pcre_OP_lengths[c];
1612        }
1613    
1614    /* Handle capturing bracket */    /* Handle capturing bracket */
1615    
1616    else if (c == OP_CBRA)    else if (c == OP_CBRA)
# Line 1446  for (;;) Line 1622  for (;;)
1622    
1623    /* 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
1624    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
1625    two bytes of parameters. */    two bytes of parameters, and for MARK/PRUNE/SKIP/THEN with an argument, we
1626      must add in its length. */
1627    
1628    else    else
1629      {      {
# Line 1470  for (;;) Line 1647  for (;;)
1647        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
1648        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
1649        break;        break;
1650    
1651          case OP_MARK:
1652          case OP_PRUNE_ARG:
1653          case OP_SKIP_ARG:
1654          case OP_THEN_ARG:
1655          code += code[1];
1656          break;
1657        }        }
1658    
1659      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
# Line 1541  for (;;) Line 1725  for (;;)
1725    
1726    /* 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
1727    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
1728    two bytes of parameters. */    two bytes of parameters, and for MARK/PRUNE/SKIP/THEN with an argument, we
1729      must add in its length. */
1730    
1731    else    else
1732      {      {
# Line 1565  for (;;) Line 1750  for (;;)
1750        case OP_TYPEEXACT:        case OP_TYPEEXACT:
1751        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
1752        break;        break;
1753    
1754          case OP_MARK:
1755          case OP_PRUNE_ARG:
1756          case OP_SKIP_ARG:
1757          case OP_THEN_ARG:
1758          code += code[1];
1759          break;
1760        }        }
1761    
1762      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
# Line 1621  Arguments: Line 1813  Arguments:
1813    code        points to start of search    code        points to start of search
1814    endcode     points to where to stop    endcode     points to where to stop
1815    utf8        TRUE if in UTF8 mode    utf8        TRUE if in UTF8 mode
1816      cd          contains pointers to tables etc.
1817    
1818  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
1819  */  */
1820    
1821  static BOOL  static BOOL
1822  could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8)  could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8,
1823      compile_data *cd)
1824  {  {
1825  register int c;  register int c;
1826  for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE);  for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE);
# Line 1657  for (code = first_significant_code(code Line 1851  for (code = first_significant_code(code
1851      continue;      continue;
1852      }      }
1853    
1854      /* For a recursion/subroutine call, if its end has been reached, which
1855      implies a subroutine call, we can scan it. */
1856    
1857      if (c == OP_RECURSE)
1858        {
1859        BOOL empty_branch = FALSE;
1860        const uschar *scode = cd->start_code + GET(code, 1);
1861        if (GET(scode, 1) == 0) return TRUE;    /* Unclosed */
1862        do
1863          {
1864          if (could_be_empty_branch(scode, endcode, utf8, cd))
1865            {
1866            empty_branch = TRUE;
1867            break;
1868            }
1869          scode += GET(scode, 1);
1870          }
1871        while (*scode == OP_ALT);
1872        if (!empty_branch) return FALSE;  /* All branches are non-empty */
1873        continue;
1874        }
1875    
1876    /* For other groups, scan the branches. */    /* For other groups, scan the branches. */
1877    
1878    if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE || c == OP_COND)    if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE || c == OP_COND)
1879      {      {
1880      BOOL empty_branch;      BOOL empty_branch;
1881      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */
1882    
1883      /* If a conditional group has only one branch, there is a second, implied,      /* If a conditional group has only one branch, there is a second, implied,
1884      empty branch, so just skip over the conditional, because it could be empty.      empty branch, so just skip over the conditional, because it could be empty.
1885      Otherwise, scan the individual branches of the group. */      Otherwise, scan the individual branches of the group. */
1886    
1887      if (c == OP_COND && code[GET(code, 1)] != OP_ALT)      if (c == OP_COND && code[GET(code, 1)] != OP_ALT)
1888        code += GET(code, 1);        code += GET(code, 1);
1889      else      else
1890        {        {
1891        empty_branch = FALSE;        empty_branch = FALSE;
1892        do        do
1893          {          {
1894          if (!empty_branch && could_be_empty_branch(code, endcode, utf8))          if (!empty_branch && could_be_empty_branch(code, endcode, utf8, cd))
1895            empty_branch = TRUE;            empty_branch = TRUE;
1896          code += GET(code, 1);          code += GET(code, 1);
1897          }          }
1898        while (*code == OP_ALT);        while (*code == OP_ALT);
1899        if (!empty_branch) return FALSE;   /* All branches are non-empty */        if (!empty_branch) return FALSE;   /* All branches are non-empty */
1900        }        }
1901    
1902      c = *code;      c = *code;
1903      continue;      continue;
1904      }      }
# Line 1800  for (code = first_significant_code(code Line 2016  for (code = first_significant_code(code
2016      case OP_QUERY:      case OP_QUERY:
2017      case OP_MINQUERY:      case OP_MINQUERY:
2018      case OP_POSQUERY:      case OP_POSQUERY:
2019        if (utf8 && code[1] >= 0xc0) code += _pcre_utf8_table4[code[1] & 0x3f];
2020        break;
2021    
2022      case OP_UPTO:      case OP_UPTO:
2023      case OP_MINUPTO:      case OP_MINUPTO:
2024      case OP_POSUPTO:      case OP_POSUPTO:
2025      if (utf8) while ((code[2] & 0xc0) == 0x80) code++;      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];
2026      break;      break;
2027  #endif  #endif
2028    
2029        /* MARK, and PRUNE/SKIP/THEN with an argument must skip over the argument
2030        string. */
2031    
2032        case OP_MARK:
2033        case OP_PRUNE_ARG:
2034        case OP_SKIP_ARG:
2035        case OP_THEN_ARG:
2036        code += code[1];
2037        break;
2038    
2039        /* None of the remaining opcodes are required to match a character. */
2040    
2041        default:
2042        break;
2043      }      }
2044    }    }
2045    
# Line 1828  Arguments: Line 2062  Arguments:
2062    endcode     points to where to stop (current RECURSE item)    endcode     points to where to stop (current RECURSE item)
2063    bcptr       points to the chain of current (unclosed) branch starts    bcptr       points to the chain of current (unclosed) branch starts
2064    utf8        TRUE if in UTF-8 mode    utf8        TRUE if in UTF-8 mode
2065      cd          pointers to tables etc
2066    
2067  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
2068  */  */
2069    
2070  static BOOL  static BOOL
2071  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,
2072    BOOL utf8)    BOOL utf8, compile_data *cd)
2073  {  {
2074  while (bcptr != NULL && bcptr->current >= code)  while (bcptr != NULL && bcptr->current_branch >= code)
2075    {    {
2076    if (!could_be_empty_branch(bcptr->current, endcode, utf8)) return FALSE;    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf8, cd))
2077        return FALSE;
2078    bcptr = bcptr->outer;    bcptr = bcptr->outer;
2079    }    }
2080  return TRUE;  return TRUE;
# Line 2500  BOOL utf8 = FALSE; Line 2736  BOOL utf8 = FALSE;
2736  uschar *utf8_char = NULL;  uschar *utf8_char = NULL;
2737  #endif  #endif
2738    
2739  #ifdef DEBUG  #ifdef PCRE_DEBUG
2740  if (lengthptr != NULL) DPRINTF((">> start branch\n"));  if (lengthptr != NULL) DPRINTF((">> start branch\n"));
2741  #endif  #endif
2742    
# Line 2559  for (;; ptr++) Line 2795  for (;; ptr++)
2795    
2796    if (lengthptr != NULL)    if (lengthptr != NULL)
2797      {      {
2798  #ifdef DEBUG  #ifdef PCRE_DEBUG
2799      if (code > cd->hwm) cd->hwm = code;                 /* High water info */      if (code > cd->hwm) cd->hwm = code;                 /* High water info */
2800  #endif  #endif
2801      if (code > cd->start_workspace + COMPILE_WORK_SIZE) /* Check for overrun */      if (code > cd->start_workspace + WORK_SIZE_CHECK)   /* Check for overrun */
2802        {        {
2803        *errorcodeptr = ERR52;        *errorcodeptr = ERR52;
2804        goto FAILED;        goto FAILED;
# Line 2611  for (;; ptr++) Line 2847  for (;; ptr++)
2847    /* 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
2848    reference list. */    reference list. */
2849    
2850    else if (cd->hwm > cd->start_workspace + COMPILE_WORK_SIZE)    else if (cd->hwm > cd->start_workspace + WORK_SIZE_CHECK)
2851      {      {
2852      *errorcodeptr = ERR52;      *errorcodeptr = ERR52;
2853      goto FAILED;      goto FAILED;
# Line 3757  we set the flag only if there is a liter Line 3993  we set the flag only if there is a liter
3993    
3994        if (repeat_max == 0) goto END_REPEAT;        if (repeat_max == 0) goto END_REPEAT;
3995    
3996          /*--------------------------------------------------------------------*/
3997          /* This code is obsolete from release 8.00; the restriction was finally
3998          removed: */
3999    
4000        /* All real repeats make it impossible to handle partial matching (maybe        /* All real repeats make it impossible to handle partial matching (maybe
4001        one day we will be able to remove this restriction). */        one day we will be able to remove this restriction). */
4002    
4003        if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL;        /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */
4004          /*--------------------------------------------------------------------*/
4005    
4006        /* Combine the op_type with the repeat_type */        /* Combine the op_type with the repeat_type */
4007    
# Line 3907  we set the flag only if there is a liter Line 4148  we set the flag only if there is a liter
4148          goto END_REPEAT;          goto END_REPEAT;
4149          }          }
4150    
4151          /*--------------------------------------------------------------------*/
4152          /* This code is obsolete from release 8.00; the restriction was finally
4153          removed: */
4154    
4155        /* All real repeats make it impossible to handle partial matching (maybe        /* All real repeats make it impossible to handle partial matching (maybe
4156        one day we will be able to remove this restriction). */        one day we will be able to remove this restriction). */
4157    
4158        if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL;        /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */
4159          /*--------------------------------------------------------------------*/
4160    
4161        if (repeat_min == 0 && repeat_max == -1)        if (repeat_min == 0 && repeat_max == -1)
4162          *code++ = OP_CRSTAR + repeat_type;          *code++ = OP_CRSTAR + repeat_type;
# Line 4045  we set the flag only if there is a liter Line 4291  we set the flag only if there is a liter
4291            {            {
4292            /* 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
4293            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
4294            potential integer overflow. */            potential integer overflow. The INT64_OR_DOUBLE type is a 64-bit
4295              integer type when available, otherwise double. */
4296    
4297            if (lengthptr != NULL)            if (lengthptr != NULL)
4298              {              {
4299              int delta = (repeat_min - 1)*length_prevgroup;              int delta = (repeat_min - 1)*length_prevgroup;
4300              if ((double)(repeat_min - 1)*(double)length_prevgroup >              if ((INT64_OR_DOUBLE)(repeat_min - 1)*
4301                                                              (double)INT_MAX ||                    (INT64_OR_DOUBLE)length_prevgroup >
4302                        (INT64_OR_DOUBLE)INT_MAX ||
4303                  OFLOW_MAX - *lengthptr < delta)                  OFLOW_MAX - *lengthptr < delta)
4304                {                {
4305                *errorcodeptr = ERR20;                *errorcodeptr = ERR20;
# Line 4097  we set the flag only if there is a liter Line 4345  we set the flag only if there is a liter
4345          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
4346          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
4347          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
4348          paranoid checks to avoid integer overflow. */          paranoid checks to avoid integer overflow. The INT64_OR_DOUBLE type is
4349            a 64-bit integer type when available, otherwise double. */
4350    
4351          if (lengthptr != NULL && repeat_max > 0)          if (lengthptr != NULL && repeat_max > 0)
4352            {            {
4353            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -
4354                        2 - 2*LINK_SIZE;   /* Last one doesn't nest */                        2 - 2*LINK_SIZE;   /* Last one doesn't nest */
4355            if ((double)repeat_max *            if ((INT64_OR_DOUBLE)repeat_max *
4356                  (double)(length_prevgroup + 1 + 2 + 2*LINK_SIZE)                  (INT64_OR_DOUBLE)(length_prevgroup + 1 + 2 + 2*LINK_SIZE)
4357                    > (double)INT_MAX ||                    > (INT64_OR_DOUBLE)INT_MAX ||
4358                OFLOW_MAX - *lengthptr < delta)                OFLOW_MAX - *lengthptr < delta)
4359              {              {
4360              *errorcodeptr = ERR20;              *errorcodeptr = ERR20;
# Line 4182  we set the flag only if there is a liter Line 4431  we set the flag only if there is a liter
4431            uschar *scode = bracode;            uschar *scode = bracode;
4432            do            do
4433              {              {
4434              if (could_be_empty_branch(scode, ketcode, utf8))              if (could_be_empty_branch(scode, ketcode, utf8, cd))
4435                {                {
4436                *bracode += OP_SBRA - OP_BRA;                *bracode += OP_SBRA - OP_BRA;
4437                break;                break;
# Line 4225  we set the flag only if there is a liter Line 4474  we set the flag only if there is a liter
4474      if (possessive_quantifier)      if (possessive_quantifier)
4475        {        {
4476        int len;        int len;
4477        if (*tempcode == OP_EXACT || *tempcode == OP_TYPEEXACT ||  
4478            *tempcode == OP_NOTEXACT)        if (*tempcode == OP_TYPEEXACT)
4479          tempcode += _pcre_OP_lengths[*tempcode] +          tempcode += _pcre_OP_lengths[*tempcode] +
4480            ((*tempcode == OP_TYPEEXACT &&            ((tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP)? 2 : 0);
4481               (tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP))? 2:0);  
4482          else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)
4483            {
4484            tempcode += _pcre_OP_lengths[*tempcode];
4485    #ifdef SUPPORT_UTF8
4486            if (utf8 && tempcode[-1] >= 0xc0)
4487              tempcode += _pcre_utf8_table4[tempcode[-1] & 0x3f];
4488    #endif
4489            }
4490    
4491        len = code - tempcode;        len = code - tempcode;
4492        if (len > 0) switch (*tempcode)        if (len > 0) switch (*tempcode)
4493          {          {
# Line 4248  we set the flag only if there is a liter Line 4506  we set the flag only if there is a liter
4506          case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;          case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;
4507          case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;          case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;
4508    
4509            /* Because we are moving code along, we must ensure that any
4510            pending recursive references are updated. */
4511    
4512          default:          default:
4513            *code = OP_END;
4514            adjust_recurse(tempcode, 1 + LINK_SIZE, utf8, cd, save_hwm);
4515          memmove(tempcode + 1+LINK_SIZE, tempcode, len);          memmove(tempcode + 1+LINK_SIZE, tempcode, len);
4516          code += 1 + LINK_SIZE;          code += 1 + LINK_SIZE;
4517          len += 1 + LINK_SIZE;          len += 1 + LINK_SIZE;
# Line 4284  we set the flag only if there is a liter Line 4547  we set the flag only if there is a liter
4547    
4548      /* First deal with various "verbs" that can be introduced by '*'. */      /* First deal with various "verbs" that can be introduced by '*'. */
4549    
4550      if (*(++ptr) == CHAR_ASTERISK && (cd->ctypes[ptr[1]] & ctype_letter) != 0)      if (*(++ptr) == CHAR_ASTERISK &&
4551             ((cd->ctypes[ptr[1]] & ctype_letter) != 0 || ptr[1] == ':'))
4552        {        {
4553        int i, namelen;        int i, namelen;
4554          int arglen = 0;
4555        const char *vn = verbnames;        const char *vn = verbnames;
4556        const uschar *name = ++ptr;        const uschar *name = ptr + 1;
4557          const uschar *arg = NULL;
4558        previous = NULL;        previous = NULL;
4559        while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};        while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};
4560          namelen = ptr - name;
4561    
4562        if (*ptr == CHAR_COLON)        if (*ptr == CHAR_COLON)
4563          {          {
4564          *errorcodeptr = ERR59;   /* Not supported */          arg = ++ptr;
4565          goto FAILED;          while ((cd->ctypes[*ptr] & (ctype_letter|ctype_digit)) != 0
4566              || *ptr == '_') ptr++;
4567            arglen = ptr - arg;
4568          }          }
4569    
4570        if (*ptr != CHAR_RIGHT_PARENTHESIS)        if (*ptr != CHAR_RIGHT_PARENTHESIS)
4571          {          {
4572          *errorcodeptr = ERR60;          *errorcodeptr = ERR60;
4573          goto FAILED;          goto FAILED;
4574          }          }
4575        namelen = ptr - name;  
4576          /* Scan the table of verb names */
4577    
4578        for (i = 0; i < verbcount; i++)        for (i = 0; i < verbcount; i++)
4579          {          {
4580          if (namelen == verbs[i].len &&          if (namelen == verbs[i].len &&
4581              strncmp((char *)name, vn, namelen) == 0)              strncmp((char *)name, vn, namelen) == 0)
4582            {            {
4583            *code = verbs[i].op;            /* Check for open captures before ACCEPT */
4584            if (*code++ == OP_ACCEPT) cd->had_accept = TRUE;  
4585            break;            if (verbs[i].op == OP_ACCEPT)
4586                {
4587                open_capitem *oc;
4588                cd->had_accept = TRUE;
4589                for (oc = cd->open_caps; oc != NULL; oc = oc->next)
4590                  {
4591                  *code++ = OP_CLOSE;
4592                  PUT2INC(code, 0, oc->number);
4593                  }
4594                }
4595    
4596              /* Handle the cases with/without an argument */
4597    
4598              if (arglen == 0)
4599                {
4600                if (verbs[i].op < 0)   /* Argument is mandatory */
4601                  {
4602                  *errorcodeptr = ERR66;
4603                  goto FAILED;
4604                  }
4605                *code++ = verbs[i].op;
4606                }
4607    
4608              else
4609                {
4610                if (verbs[i].op_arg < 0)   /* Argument is forbidden */
4611                  {
4612                  *errorcodeptr = ERR59;
4613                  goto FAILED;
4614                  }
4615                *code++ = verbs[i].op_arg;
4616                *code++ = arglen;
4617                memcpy(code, arg, arglen);
4618                code += arglen;
4619                *code++ = 0;
4620                }
4621    
4622              break;  /* Found verb, exit loop */
4623            }            }
4624    
4625          vn += verbs[i].len + 1;          vn += verbs[i].len + 1;
4626          }          }
4627        if (i < verbcount) continue;  
4628        *errorcodeptr = ERR60;        if (i < verbcount) continue;    /* Successfully handled a verb */
4629          *errorcodeptr = ERR60;          /* Verb not recognized */
4630        goto FAILED;        goto FAILED;
4631        }        }
4632    
# Line 4470  we set the flag only if there is a liter Line 4782  we set the flag only if there is a liter
4782            }            }
4783    
4784          /* Otherwise (did not start with "+" or "-"), start by looking for the          /* Otherwise (did not start with "+" or "-"), start by looking for the
4785          name. */          name. If we find a name, add one to the opcode to change OP_CREF or
4786            OP_RREF into OP_NCREF or OP_NRREF. These behave exactly the same,
4787            except they record that the reference was originally to a name. The
4788            information is used to check duplicate names. */
4789    
4790          slot = cd->name_table;          slot = cd->name_table;
4791          for (i = 0; i < cd->names_found; i++)          for (i = 0; i < cd->names_found; i++)
# Line 4485  we set the flag only if there is a liter Line 4800  we set the flag only if there is a liter
4800            {            {
4801            recno = GET2(slot, 0);            recno = GET2(slot, 0);
4802            PUT2(code, 2+LINK_SIZE, recno);            PUT2(code, 2+LINK_SIZE, recno);
4803              code[1+LINK_SIZE]++;
4804            }            }
4805    
4806          /* Search the pattern for a forward reference */          /* Search the pattern for a forward reference */
4807    
4808          else if ((i = find_parens(ptr, cd, name, namelen,          else if ((i = find_parens(cd, name, namelen,
4809                          (options & PCRE_EXTENDED) != 0)) > 0)                          (options & PCRE_EXTENDED) != 0)) > 0)
4810            {            {
4811            PUT2(code, 2+LINK_SIZE, i);            PUT2(code, 2+LINK_SIZE, i);
4812              code[1+LINK_SIZE]++;
4813            }            }
4814    
4815          /* If terminator == 0 it means that the name followed directly after          /* If terminator == 0 it means that the name followed directly after
# Line 4685  we set the flag only if there is a liter Line 5002  we set the flag only if there is a liter
5002                }                }
5003              }              }
5004    
5005            /* In the real compile, create the entry in the table */            /* In the real compile, create the entry in the table, maintaining
5006              alphabetical order. Duplicate names for different numbers are
5007              permitted only if PCRE_DUPNAMES is set. Duplicate names for the same
5008              number are always OK. (An existing number can be re-used if (?|
5009              appears in the pattern.) In either event, a duplicate name results in
5010              a duplicate entry in the table, even if the number is the same. This
5011              is because the number of names, and hence the table size, is computed
5012              in the pre-compile, and it affects various numbers and pointers which
5013              would all have to be modified, and the compiled code moved down, if
5014              duplicates with the same number were omitted from the table. This
5015              doesn't seem worth the hassle. However, *different* names for the
5016              same number are not permitted. */
5017    
5018            else            else
5019              {              {
5020                BOOL dupname = FALSE;
5021              slot = cd->name_table;              slot = cd->name_table;
5022    
5023              for (i = 0; i < cd->names_found; i++)              for (i = 0; i < cd->names_found; i++)
5024                {                {
5025                int crc = memcmp(name, slot+2, namelen);                int crc = memcmp(name, slot+2, namelen);
# Line 4697  we set the flag only if there is a liter Line 5027  we set the flag only if there is a liter
5027                  {                  {
5028                  if (slot[2+namelen] == 0)                  if (slot[2+namelen] == 0)
5029                    {                    {
5030                    if ((options & PCRE_DUPNAMES) == 0)                    if (GET2(slot, 0) != cd->bracount + 1 &&
5031                          (options & PCRE_DUPNAMES) == 0)
5032                      {                      {
5033                      *errorcodeptr = ERR43;                      *errorcodeptr = ERR43;
5034                      goto FAILED;                      goto FAILED;
5035                      }                      }
5036                      else dupname = TRUE;
5037                    }                    }
5038                  else crc = -1;      /* Current name is substring */                  else crc = -1;      /* Current name is a substring */
5039                  }                  }
5040    
5041                  /* Make space in the table and break the loop for an earlier
5042                  name. For a duplicate or later name, carry on. We do this for
5043                  duplicates so that in the simple case (when ?(| is not used) they
5044                  are in order of their numbers. */
5045    
5046                if (crc < 0)                if (crc < 0)
5047                  {                  {
5048                  memmove(slot + cd->name_entry_size, slot,                  memmove(slot + cd->name_entry_size, slot,
5049                    (cd->names_found - i) * cd->name_entry_size);                    (cd->names_found - i) * cd->name_entry_size);
5050                  break;                  break;
5051                  }                  }
5052    
5053                  /* Continue the loop for a later or duplicate name */
5054    
5055                slot += cd->name_entry_size;                slot += cd->name_entry_size;
5056                }                }
5057    
5058                /* For non-duplicate names, check for a duplicate number before
5059                adding the new name. */
5060    
5061                if (!dupname)
5062                  {
5063                  uschar *cslot = cd->name_table;
5064                  for (i = 0; i < cd->names_found; i++)
5065                    {
5066                    if (cslot != slot)
5067                      {
5068                      if (GET2(cslot, 0) == cd->bracount + 1)
5069                        {
5070                        *errorcodeptr = ERR65;
5071                        goto FAILED;
5072                        }
5073                      }
5074                    else i--;
5075                    cslot += cd->name_entry_size;
5076                    }
5077                  }
5078    
5079              PUT2(slot, 0, cd->bracount + 1);              PUT2(slot, 0, cd->bracount + 1);
5080              memcpy(slot + 2, name, namelen);              memcpy(slot + 2, name, namelen);
5081              slot[2+namelen] = 0;              slot[2+namelen] = 0;
5082              }              }
5083            }            }
5084    
5085          /* In both cases, count the number of names we've encountered. */          /* In both pre-compile and compile, count the number of names we've
5086            encountered. */
5087    
         ptr++;                    /* Move past > or ' */  
5088          cd->names_found++;          cd->names_found++;
5089            ptr++;                    /* Move past > or ' */
5090          goto NUMBERED_GROUP;          goto NUMBERED_GROUP;
5091    
5092    
# Line 4788  we set the flag only if there is a liter Line 5151  we set the flag only if there is a liter
5151              recno = GET2(slot, 0);              recno = GET2(slot, 0);
5152              }              }
5153            else if ((recno =                /* Forward back reference */            else if ((recno =                /* Forward back reference */
5154                      find_parens(ptr, cd, name, namelen,                      find_parens(cd, name, namelen,
5155                        (options & PCRE_EXTENDED) != 0)) <= 0)                        (options & PCRE_EXTENDED) != 0)) <= 0)
5156              {              {
5157              *errorcodeptr = ERR15;              *errorcodeptr = ERR15;
# Line 4892  we set the flag only if there is a liter Line 5255  we set the flag only if there is a liter
5255            if (lengthptr == NULL)            if (lengthptr == NULL)
5256              {              {
5257              *code = OP_END;              *code = OP_END;
5258              if (recno != 0) called = find_bracket(cd->start_code, utf8, recno);              if (recno != 0)
5259                  called = _pcre_find_bracket(cd->start_code, utf8, recno);
5260    
5261              /* Forward reference */              /* Forward reference */
5262    
5263              if (called == NULL)              if (called == NULL)
5264                {                {
5265                if (find_parens(ptr, cd, NULL, recno,                if (find_parens(cd, NULL, recno,
5266                      (options & PCRE_EXTENDED) != 0) < 0)                      (options & PCRE_EXTENDED) != 0) < 0)
5267                  {                  {
5268                  *errorcodeptr = ERR15;                  *errorcodeptr = ERR15;
5269                  goto FAILED;                  goto FAILED;
5270                  }                  }
5271    
5272                  /* Fudge the value of "called" so that when it is inserted as an
5273                  offset below, what it actually inserted is the reference number
5274                  of the group. */
5275    
5276                called = cd->start_code + recno;                called = cd->start_code + recno;
5277                PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code);                PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code);
5278                }                }
# Line 4913  we set the flag only if there is a liter Line 5282  we set the flag only if there is a liter
5282              recursion that could loop for ever, and diagnose that case. */              recursion that could loop for ever, and diagnose that case. */
5283    
5284              else if (GET(called, 1) == 0 &&              else if (GET(called, 1) == 0 &&
5285                       could_be_empty(called, code, bcptr, utf8))                       could_be_empty(called, code, bcptr, utf8, cd))
5286                {                {
5287                *errorcodeptr = ERR40;                *errorcodeptr = ERR40;
5288                goto FAILED;                goto FAILED;
# Line 5008  we set the flag only if there is a liter Line 5377  we set the flag only if there is a liter
5377              {              {
5378              cd->external_options = newoptions;              cd->external_options = newoptions;
5379              }              }
5380           else            else
5381              {              {
5382              if ((options & PCRE_IMS) != (newoptions & PCRE_IMS))              if ((options & PCRE_IMS) != (newoptions & PCRE_IMS))
5383                {                {
# Line 5040  we set the flag only if there is a liter Line 5409  we set the flag only if there is a liter
5409          }     /* End of switch for character following (? */          }     /* End of switch for character following (? */
5410        }       /* End of (? handling */        }       /* End of (? handling */
5411    
5412      /* Opening parenthesis not followed by '?'. If PCRE_NO_AUTO_CAPTURE is set,      /* Opening parenthesis not followed by '*' or '?'. If PCRE_NO_AUTO_CAPTURE
5413      all unadorned brackets become non-capturing and behave like (?:...)      is set, all unadorned brackets become non-capturing and behave like (?:...)
5414      brackets. */      brackets. */
5415    
5416      else if ((options & PCRE_NO_AUTO_CAPTURE) != 0)      else if ((options & PCRE_NO_AUTO_CAPTURE) != 0)
# Line 5345  we set the flag only if there is a liter Line 5714  we set the flag only if there is a liter
5714    
5715        if (-c >= ESC_REF)        if (-c >= ESC_REF)
5716          {          {
5717            open_capitem *oc;
5718          recno = -c - ESC_REF;          recno = -c - ESC_REF;
5719    
5720          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
# Line 5354  we set the flag only if there is a liter Line 5724  we set the flag only if there is a liter
5724          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
5725          cd->backref_map |= (recno < 32)? (1 << recno) : 1;          cd->backref_map |= (recno < 32)? (1 << recno) : 1;
5726          if (recno > cd->top_backref) cd->top_backref = recno;          if (recno > cd->top_backref) cd->top_backref = recno;
5727    
5728            /* Check to see if this back reference is recursive, that it, it
5729            is inside the group that it references. A flag is set so that the
5730            group can be made atomic. */
5731    
5732            for (oc = cd->open_caps; oc != NULL; oc = oc->next)
5733              {
5734              if (oc->number == recno)
5735                {
5736                oc->flag = TRUE;
5737                break;
5738                }
5739              }
5740          }          }
5741    
5742        /* So are Unicode property matches, if supported. */        /* So are Unicode property matches, if supported. */
# Line 5536  uschar *code = *codeptr; Line 5919  uschar *code = *codeptr;
5919  uschar *last_branch = code;  uschar *last_branch = code;
5920  uschar *start_bracket = code;  uschar *start_bracket = code;
5921  uschar *reverse_count = NULL;  uschar *reverse_count = NULL;
5922    open_capitem capitem;
5923    int capnumber = 0;
5924  int firstbyte, reqbyte;  int firstbyte, reqbyte;
5925  int branchfirstbyte, branchreqbyte;  int branchfirstbyte, branchreqbyte;
5926  int length;  int length;
5927  int orig_bracount;  int orig_bracount;
5928  int max_bracount;  int max_bracount;
5929    int old_external_options = cd->external_options;
5930  branch_chain bc;  branch_chain bc;
5931    
5932  bc.outer = bcptr;  bc.outer = bcptr;
5933  bc.current = code;  bc.current_branch = code;
5934    
5935  firstbyte = reqbyte = REQ_UNSET;  firstbyte = reqbyte = REQ_UNSET;
5936    
# Line 5562  the code that abstracts option settings Line 5948  the code that abstracts option settings
5948  them global. It tests the value of length for (2 + 2*LINK_SIZE) in the  them global. It tests the value of length for (2 + 2*LINK_SIZE) in the
5949  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. */
5950    
5951    /* If this is a capturing subpattern, add to the chain of open capturing items
5952    so that we can detect them if (*ACCEPT) is encountered. This is also used to
5953    detect groups that contain recursive back references to themselves. */
5954    
5955    if (*code == OP_CBRA)
5956      {
5957      capnumber = GET2(code, 1 + LINK_SIZE);
5958      capitem.number = capnumber;
5959      capitem.next = cd->open_caps;
5960      capitem.flag = FALSE;
5961      cd->open_caps = &capitem;
5962      }
5963    
5964  /* Offset is set zero to mark that this bracket is still open */  /* Offset is set zero to mark that this bracket is still open */
5965    
5966  PUT(code, 1, 0);  PUT(code, 1, 0);
# Line 5606  for (;;) Line 6005  for (;;)
6005      return FALSE;      return FALSE;
6006      }      }
6007    
6008      /* If the external options have changed during this branch, it means that we
6009      are at the top level, and a leading option setting has been encountered. We
6010      need to re-set the original option values to take account of this so that,
6011      during the pre-compile phase, we know to allow for a re-set at the start of
6012      subsequent branches. */
6013    
6014      if (old_external_options != cd->external_options)
6015        oldims = cd->external_options & PCRE_IMS;
6016    
6017    /* Keep the highest bracket count in case (?| was used and some branch    /* Keep the highest bracket count in case (?| was used and some branch
6018    has fewer than the rest. */    has fewer than the rest. */
6019    
# Line 5656  for (;;) Line 6064  for (;;)
6064    
6065      /* If lookbehind, check that this branch matches a fixed-length string, and      /* If lookbehind, check that this branch matches a fixed-length string, and
6066      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
6067      branch with OP_END. */      branch with OP_END. If the branch contains OP_RECURSE, the result is -3
6068        because there may be forward references that we can't check here. Set a
6069        flag to cause another lookbehind check at the end. Why not do it all at the
6070        end? Because common, erroneous checks are picked up here and the offset of
6071        the problem can be shown. */
6072    
6073      if (lookbehind)      if (lookbehind)
6074        {        {
6075        int fixed_length;        int fixed_length;
6076        *code = OP_END;        *code = OP_END;
6077        fixed_length = find_fixedlength(last_branch, options);        fixed_length = find_fixedlength(last_branch, options, FALSE, cd);
6078        DPRINTF(("fixed length = %d\n", fixed_length));        DPRINTF(("fixed length = %d\n", fixed_length));
6079        if (fixed_length < 0)        if (fixed_length == -3)
6080            {
6081            cd->check_lookbehind = TRUE;
6082            }
6083          else if (fixed_length < 0)
6084          {          {
6085          *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25;          *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25;
6086          *ptrptr = ptr;          *ptrptr = ptr;
6087          return FALSE;          return FALSE;
6088          }          }
6089        PUT(reverse_count, 0, fixed_length);        else { PUT(reverse_count, 0, fixed_length); }
6090        }        }
6091      }      }
6092    
# Line 5704  for (;;) Line 6120  for (;;)
6120      PUT(code, 1, code - start_bracket);      PUT(code, 1, code - start_bracket);
6121      code += 1 + LINK_SIZE;      code += 1 + LINK_SIZE;
6122    
6123      /* Resetting option if needed */      /* If it was a capturing subpattern, check to see if it contained any
6124        recursive back references. If so, we must wrap it in atomic brackets.
6125        In any event, remove the block from the chain. */
6126    
6127        if (capnumber > 0)
6128          {
6129          if (cd->open_caps->flag)
6130            {
6131            memmove(start_bracket + 1 + LINK_SIZE, start_bracket,
6132              code - start_bracket);
6133            *start_bracket = OP_ONCE;
6134            code += 1 + LINK_SIZE;
6135            PUT(start_bracket, 1, code - start_bracket);
6136            *code = OP_KET;
6137            PUT(code, 1, code - start_bracket);
6138            code += 1 + LINK_SIZE;
6139            length += 2 + 2*LINK_SIZE;
6140            }
6141          cd->open_caps = cd->open_caps->next;
6142          }
6143    
6144        /* Reset options if needed. */
6145    
6146      if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS)      if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS)
6147        {        {
# Line 5753  for (;;) Line 6190  for (;;)
6190      {      {
6191      *code = OP_ALT;      *code = OP_ALT;
6192      PUT(code, 1, code - last_branch);      PUT(code, 1, code - last_branch);
6193      bc.current = last_branch = code;      bc.current_branch = last_branch = code;
6194      code += 1 + LINK_SIZE;      code += 1 + LINK_SIZE;
6195      }      }
6196    
# Line 5900  do { Line 6337  do {
6337       switch (*scode)       switch (*scode)
6338         {         {
6339         case OP_CREF:         case OP_CREF:
6340           case OP_NCREF:
6341         case OP_RREF:         case OP_RREF:
6342           case OP_NRREF:
6343         case OP_DEF:         case OP_DEF:
6344         return FALSE;         return FALSE;
6345    
# Line 6069  int length = 1;  /* For final END opcode Line 6508  int length = 1;  /* For final END opcode
6508  int firstbyte, reqbyte, newline;  int firstbyte, reqbyte, newline;
6509  int errorcode = 0;  int errorcode = 0;
6510  int skipatstart = 0;  int skipatstart = 0;
6511  #ifdef SUPPORT_UTF8  BOOL utf8 = (options & PCRE_UTF8) != 0;
 BOOL utf8;  
 #endif  
6512  size_t size;  size_t size;
6513  uschar *code;  uschar *code;
6514  const uschar *codestart;  const uschar *codestart;
# Line 6114  if (erroroffset == NULL) Line 6551  if (erroroffset == NULL)
6551    
6552  *erroroffset = 0;  *erroroffset = 0;
6553    
 /* Can't support UTF8 unless PCRE has been compiled to include the code. */  
   
 #ifdef SUPPORT_UTF8  
 utf8 = (options & PCRE_UTF8) != 0;  
 if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&  
      (*erroroffset = _pcre_valid_utf8((uschar *)pattern, -1)) >= 0)  
   {  
   errorcode = ERR44;  
   goto PCRE_EARLY_ERROR_RETURN2;  
   }  
 #else  
 if ((options & PCRE_UTF8) != 0)  
   {  
   errorcode = ERR32;  
   goto PCRE_EARLY_ERROR_RETURN;  
   }  
 #endif  
   
 if ((options & ~PUBLIC_COMPILE_OPTIONS) != 0)  
   {  
   errorcode = ERR17;  
   goto PCRE_EARLY_ERROR_RETURN;  
   }  
   
6554  /* Set up pointers to the individual character tables */  /* Set up pointers to the individual character tables */
6555    
6556  if (tables == NULL) tables = _pcre_default_tables;  if (tables == NULL) tables = _pcre_default_tables;
# Line 6146  cd->fcc = tables + fcc_offset; Line 6559  cd->fcc = tables + fcc_offset;
6559  cd->cbits = tables + cbits_offset;  cd->cbits = tables + cbits_offset;
6560  cd->ctypes = tables + ctypes_offset;  cd->ctypes = tables + ctypes_offset;
6561    
6562    /* Check that all undefined public option bits are zero */
6563    
6564    if ((options & ~PUBLIC_COMPILE_OPTIONS) != 0)
6565      {
6566      errorcode = ERR17;
6567      goto PCRE_EARLY_ERROR_RETURN;
6568      }
6569    
6570  /* Check for global one-time settings at the start of the pattern, and remember  /* Check for global one-time settings at the start of the pattern, and remember
6571  the offset for later. */  the offset for later. */
6572    
# Line 6155  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 6576  while (ptr[skipatstart] == CHAR_LEFT_PAR
6576    int newnl = 0;    int newnl = 0;
6577    int newbsr = 0;    int newbsr = 0;
6578    
6579      if (strncmp((char *)(ptr+skipatstart+2), STRING_UTF8_RIGHTPAR, 5) == 0)
6580        { skipatstart += 7; options |= PCRE_UTF8; continue; }
6581    
6582    if (strncmp((char *)(ptr+skipatstart+2), STRING_CR_RIGHTPAR, 3) == 0)    if (strncmp((char *)(ptr+skipatstart+2), STRING_CR_RIGHTPAR, 3) == 0)
6583      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
6584    else if (strncmp((char *)(ptr+skipatstart+2), STRING_LF_RIGHTPAR, 3)  == 0)    else if (strncmp((char *)(ptr+skipatstart+2), STRING_LF_RIGHTPAR, 3)  == 0)
# Line 6178  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 6602  while (ptr[skipatstart] == CHAR_LEFT_PAR
6602    else break;    else break;
6603    }    }
6604    
6605    /* Can't support UTF8 unless PCRE has been compiled to include the code. */
6606    
6607    #ifdef SUPPORT_UTF8
6608    if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&
6609         (*erroroffset = _pcre_valid_utf8((USPTR)pattern, -1)) >= 0)
6610      {
6611      errorcode = ERR44;
6612      goto PCRE_EARLY_ERROR_RETURN2;
6613      }
6614    #else
6615    if (utf8)
6616      {
6617      errorcode = ERR32;
6618      goto PCRE_EARLY_ERROR_RETURN;
6619      }
6620    #endif
6621    
6622  /* Check validity of \R options. */  /* Check validity of \R options. */
6623    
6624  switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))  switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
# Line 6260  cd->end_pattern = (const uschar *)(patte Line 6701  cd->end_pattern = (const uschar *)(patte
6701  cd->req_varyopt = 0;  cd->req_varyopt = 0;
6702  cd->external_options = options;  cd->external_options = options;
6703  cd->external_flags = 0;  cd->external_flags = 0;
6704    cd->open_caps = NULL;
6705    
6706  /* Now do the pre-compile. On error, errorcode will be set non-zero, so we  /* Now do the pre-compile. On error, errorcode will be set non-zero, so we
6707  don't need to look at the result of the function here. The initial options have  don't need to look at the result of the function here. The initial options have
# Line 6334  cd->start_code = codestart; Line 6776  cd->start_code = codestart;
6776  cd->hwm = cworkspace;  cd->hwm = cworkspace;
6777  cd->req_varyopt = 0;  cd->req_varyopt = 0;
6778  cd->had_accept = FALSE;  cd->had_accept = FALSE;
6779    cd->check_lookbehind = FALSE;
6780    cd->open_caps = NULL;
6781    
6782  /* Set up a starting, non-extracting bracket, then compile the expression. On  /* Set up a starting, non-extracting bracket, then compile the expression. On
6783  error, errorcode will be set non-zero, so we don't need to look at the result  error, errorcode will be set non-zero, so we don't need to look at the result
# Line 6359  if debugging, leave the test till after Line 6803  if debugging, leave the test till after
6803    
6804  *code++ = OP_END;  *code++ = OP_END;
6805    
6806  #ifndef DEBUG  #ifndef PCRE_DEBUG
6807  if (code - codestart > length) errorcode = ERR23;  if (code - codestart > length) errorcode = ERR23;
6808  #endif  #endif
6809    
# Line 6372  while (errorcode == 0 && cd->hwm > cwork Line 6816  while (errorcode == 0 && cd->hwm > cwork
6816    cd->hwm -= LINK_SIZE;    cd->hwm -= LINK_SIZE;
6817    offset = GET(cd->hwm, 0);    offset = GET(cd->hwm, 0);
6818    recno = GET(codestart, offset);    recno = GET(codestart, offset);
6819    groupptr = find_bracket(codestart, (re->options & PCRE_UTF8) != 0, recno);    groupptr = _pcre_find_bracket(codestart, utf8, recno);
6820    if (groupptr == NULL) errorcode = ERR53;    if (groupptr == NULL) errorcode = ERR53;
6821      else PUT(((uschar *)codestart), offset, groupptr - codestart);      else PUT(((uschar *)codestart), offset, groupptr - codestart);
6822    }    }
# Line 6382  subpattern. */ Line 6826  subpattern. */
6826    
6827  if (errorcode == 0 && re->top_backref > re->top_bracket) errorcode = ERR15;  if (errorcode == 0 && re->top_backref > re->top_bracket) errorcode = ERR15;
6828    
6829    /* If there were any lookbehind assertions that contained OP_RECURSE
6830    (recursions or subroutine calls), a flag is set for them to be checked here,
6831    because they may contain forward references. Actual recursions can't be fixed
6832    length, but subroutine calls can. It is done like this so that those without
6833    OP_RECURSE that are not fixed length get a diagnosic with a useful offset. The
6834    exceptional ones forgo this. We scan the pattern to check that they are fixed
6835    length, and set their lengths. */
6836    
6837    if (cd->check_lookbehind)
6838      {
6839      uschar *cc = (uschar *)codestart;
6840    
6841      /* Loop, searching for OP_REVERSE items, and process those that do not have
6842      their length set. (Actually, it will also re-process any that have a length
6843      of zero, but that is a pathological case, and it does no harm.) When we find
6844      one, we temporarily terminate the branch it is in while we scan it. */
6845    
6846      for (cc = (uschar *)_pcre_find_bracket(codestart, utf8, -1);
6847           cc != NULL;
6848           cc = (uschar *)_pcre_find_bracket(cc, utf8, -1))
6849        {
6850        if (GET(cc, 1) == 0)
6851          {
6852          int fixed_length;
6853          uschar *be = cc - 1 - LINK_SIZE + GET(cc, -LINK_SIZE);
6854          int end_op = *be;
6855          *be = OP_END;
6856          fixed_length = find_fixedlength(cc, re->options, TRUE, cd);
6857          *be = end_op;
6858          DPRINTF(("fixed length = %d\n", fixed_length));
6859          if (fixed_length < 0)
6860            {
6861            errorcode = (fixed_length == -2)? ERR36 : ERR25;
6862            break;
6863            }
6864          PUT(cc, 1, fixed_length);
6865          }
6866        cc += 1 + LINK_SIZE;
6867        }
6868      }
6869    
6870  /* Failed to compile, or error while post-processing */  /* Failed to compile, or error while post-processing */
6871    
6872  if (errorcode != 0)  if (errorcode != 0)
# Line 6442  if (reqbyte >= 0 && Line 6927  if (reqbyte >= 0 &&
6927  /* 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
6928  case when building a production library. */  case when building a production library. */
6929    
6930  #ifdef DEBUG  #ifdef PCRE_DEBUG
   
6931  printf("Length = %d top_bracket = %d top_backref = %d\n",  printf("Length = %d top_bracket = %d top_backref = %d\n",
6932    length, re->top_bracket, re->top_backref);    length, re->top_bracket, re->top_backref);
6933    
# Line 6480  if (code - codestart > length) Line 6964  if (code - codestart > length)
6964    if (errorcodeptr != NULL) *errorcodeptr = ERR23;    if (errorcodeptr != NULL) *errorcodeptr = ERR23;
6965    return NULL;    return NULL;
6966    }    }
6967  #endif   /* DEBUG */  #endif   /* PCRE_DEBUG */
6968    
6969  return (pcre *)re;  return (pcre *)re;
6970  }  }

Legend:
Removed from v.395  
changed lines
  Added in v.512

  ViewVC Help
Powered by ViewVC 1.1.5