/[pcre]/code/tags/pcre-7.1/pcre_compile.c
ViewVC logotype

Diff of /code/tags/pcre-7.1/pcre_compile.c

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

revision 79 by nigel, Sat Feb 24 21:40:52 2007 UTC revision 81 by nigel, Sat Feb 24 21:40:59 2007 UTC
# Line 698  read_repeat_counts(const uschar *p, int Line 698  read_repeat_counts(const uschar *p, int
698  int min = 0;  int min = 0;
699  int max = -1;  int max = -1;
700    
701    /* Read the minimum value and do a paranoid check: a negative value indicates
702    an integer overflow. */
703    
704  while ((digitab[*p] & ctype_digit) != 0) min = min * 10 + *p++ - '0';  while ((digitab[*p] & ctype_digit) != 0) min = min * 10 + *p++ - '0';
705    if (min < 0 || min > 65535)
706      {
707      *errorcodeptr = ERR5;
708      return p;
709      }
710    
711    /* Read the maximum value if there is one, and again do a paranoid on its size.
712    Also, max must not be less than min. */
713    
714  if (*p == '}') max = min; else  if (*p == '}') max = min; else
715    {    {
# Line 706  if (*p == '}') max = min; else Line 717  if (*p == '}') max = min; else
717      {      {
718      max = 0;      max = 0;
719      while((digitab[*p] & ctype_digit) != 0) max = max * 10 + *p++ - '0';      while((digitab[*p] & ctype_digit) != 0) max = max * 10 + *p++ - '0';
720        if (max < 0 || max > 65535)
721          {
722          *errorcodeptr = ERR5;
723          return p;
724          }
725      if (max < min)      if (max < min)
726        {        {
727        *errorcodeptr = ERR4;        *errorcodeptr = ERR4;
# Line 714  if (*p == '}') max = min; else Line 730  if (*p == '}') max = min; else
730      }      }
731    }    }
732    
733  /* Do paranoid checks, then fill in the required variables, and pass back the  /* Fill in the required variables, and pass back the pointer to the terminating
734  pointer to the terminating '}'. */  '}'. */
735    
736  if (min > 65535 || max > 65535)  *minp = min;
737    *errorcodeptr = ERR5;  *maxp = max;
 else  
   {  
   *minp = min;  
   *maxp = max;  
   }  
738  return p;  return p;
739  }  }
740    
# Line 3856  BOOL utf8; Line 3867  BOOL utf8;
3867  BOOL class_utf8;  BOOL class_utf8;
3868  #endif  #endif
3869  BOOL inescq = FALSE;  BOOL inescq = FALSE;
3870    BOOL capturing;
3871  unsigned int brastackptr = 0;  unsigned int brastackptr = 0;
3872  size_t size;  size_t size;
3873  uschar *code;  uschar *code;
# Line 4410  while ((c = *(++ptr)) != 0) Line 4422  while ((c = *(++ptr)) != 0)
4422      case '(':      case '(':
4423      branch_newextra = 0;      branch_newextra = 0;
4424      bracket_length = 1 + LINK_SIZE;      bracket_length = 1 + LINK_SIZE;
4425        capturing = FALSE;
4426    
4427      /* Handle special forms of bracket, which all start (? */      /* Handle special forms of bracket, which all start (? */
4428    
# Line 4497  while ((c = *(++ptr)) != 0) Line 4510  while ((c = *(++ptr)) != 0)
4510    
4511          case 'P':          case 'P':
4512          ptr += 3;          ptr += 3;
4513    
4514            /* Handle the definition of a named subpattern */
4515    
4516          if (*ptr == '<')          if (*ptr == '<')
4517            {            {
4518            const uschar *p;    /* Don't amalgamate; some compilers */            const uschar *p;    /* Don't amalgamate; some compilers */
# Line 4509  while ((c = *(++ptr)) != 0) Line 4525  while ((c = *(++ptr)) != 0)
4525              }              }
4526            name_count++;            name_count++;
4527            if (ptr - p > max_name_size) max_name_size = (ptr - p);            if (ptr - p > max_name_size) max_name_size = (ptr - p);
4528              capturing = TRUE;   /* Named parentheses are always capturing */
4529            break;            break;
4530            }            }
4531    
4532            /* Handle back references and recursive calls to named subpatterns */
4533    
4534          if (*ptr == '=' || *ptr == '>')          if (*ptr == '=' || *ptr == '>')
4535            {            {
4536            while ((compile_block.ctypes[*(++ptr)] & ctype_word) != 0);            while ((compile_block.ctypes[*(++ptr)] & ctype_word) != 0);
# Line 4695  while ((c = *(++ptr)) != 0) Line 4714  while ((c = *(++ptr)) != 0)
4714            continue;            continue;
4715            }            }
4716    
4717          /* If options were terminated by ':' control comes here. Fall through          /* If options were terminated by ':' control comes here. This is a
4718          to handle the group below. */          non-capturing group with an options change. There is nothing more that
4719            needs to be done because "capturing" is already set FALSE by default;
4720            we can just fall through. */
4721    
4722          }          }
4723        }        }
4724    
4725      /* Extracting brackets must be counted so we can process escapes in a      /* Ordinary parentheses, not followed by '?', are capturing unless
4726      Perlish way. If the number exceeds EXTRACT_BASIC_MAX we are going to      PCRE_NO_AUTO_CAPTURE is set. */
4727      need an additional 3 bytes of store per extracting bracket. However, if  
4728      PCRE_NO_AUTO)CAPTURE is set, unadorned brackets become non-capturing, so we      else capturing = (options & PCRE_NO_AUTO_CAPTURE) == 0;
4729      must leave the count alone (it will aways be zero). */  
4730        /* Capturing brackets must be counted so we can process escapes in a
4731        Perlish way. If the number exceeds EXTRACT_BASIC_MAX we are going to need
4732        an additional 3 bytes of memory per capturing bracket. */
4733    
4734      else if ((options & PCRE_NO_AUTO_CAPTURE) == 0)      if (capturing)
4735        {        {
4736        bracount++;        bracount++;
4737        if (bracount > EXTRACT_BASIC_MAX) bracket_length += 3;        if (bracount > EXTRACT_BASIC_MAX) bracket_length += 3;

Legend:
Removed from v.79  
changed lines
  Added in v.81

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12