PennMUSH Community

Changeset 1145

Show
Ignore:
Timestamp:
11/15/07 07:43:14 (1 year ago)
Author:
shawnw
Message:

#7482: Force low match_limit setting with sys pcre

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/hdrs/mypcre.h

    r1143 r1145  
     1#ifndef _MYPCRE_H 
     2#define _MYPCRE_H 
     3 
    14/************************************************* 
    25*       Perl-Compatible Regular Expressions      * 
     
    4043   pcre.c for details. */ 
    4144 
     45 
     46#define PENN_MATCH_LIMIT 100000 
     47struct pcre_extra; 
     48void set_match_limit(struct pcre_extra *); 
     49struct pcre_extra * default_match_limit(void); 
     50 
    4251#ifdef HAVE_PCRE 
    4352#include <pcre.h> 
    4453#else 
    4554 
    46 #ifndef _PCRE_H 
    47 #define _PCRE_H 
    4855 
    4956#define PCRE_MAJOR          6 
     
    205212}                               /* extern "C" */ 
    206213#endif 
     214#endif                          /* !HAVE_PCRE */ 
    207215#endif                          /* End of pcre.h */ 
    208 #endif                          /* !HAVE_PCRE */ 
     216 
  • 1.8.3/branches/devel/src/funlist.c

    r1143 r1145  
    26752675{ 
    26762676  pcre *re; 
    2677   pcre_extra *study = NULL; 
     2677  pcre_extra *extra, *study = NULL; 
    26782678  const char *errptr; 
    26792679  int subpatterns; 
     
    27472747      study = pcre_study(re, 0, &errptr); 
    27482748      if (errptr != NULL) { 
    2749         mush_free((Malloc_t) re, "pcre"); 
     2749        mush_free(re, "pcre"); 
    27502750        safe_str(T("#-1 REGEXP ERROR: "), buff, bp); 
    27512751        safe_str(errptr, buff, bp); 
     
    27592759    } 
    27602760 
     2761    if (study) { 
     2762      extra = study; 
     2763      set_match_limit(extra); 
     2764    } else 
     2765      extra = default_match_limit(); 
     2766 
    27612767    search = 0; 
    27622768    /* Do all the searches and replaces we can */ 
    27632769 
    27642770    start = prebuf; 
    2765     subpatterns = pcre_exec(re, study, prebuf, prelen, 0, 0, offsets, 99); 
     2771    subpatterns = pcre_exec(re, extra, prebuf, prelen, 0, 0, offsets, 99); 
    27662772 
    27672773    /* Match wasn't found... we're done */ 
    27682774    if (subpatterns < 0) { 
    27692775      safe_str(prebuf, postbuf, &postp); 
    2770       mush_free((Malloc_t) re, "pcre"); 
     2776      mush_free(re, "pcre"); 
    27712777      free_ansi_string(orig); 
    27722778      if (study) 
    2773         mush_free((Malloc_t) study, "pcre.extra"); 
     2779        mush_free(study, "pcre.extra"); 
    27742780      continue; 
    27752781    } 
     
    28052811        match_offset++; 
    28062812    } while (all && match_offset < prelen && 
    2807              (subpatterns = pcre_exec(re, study, prebuf, prelen, 
     2813             (subpatterns = pcre_exec(re, extra, prebuf, prelen, 
    28082814                                      match_offset, 0, offsets, 99)) >= 0); 
    28092815 
     
    28112817    *postp = '\0'; 
    28122818 
    2813     mush_free((Malloc_t) re, "pcre"); 
     2819    mush_free(re, "pcre"); 
    28142820    if (study != NULL) 
    2815       mush_free((Malloc_t) study, "pcre.extra"); 
     2821      mush_free(study, "pcre.extra"); 
    28162822    free_ansi_string(orig); 
    28172823  } 
     
    28492855        study = pcre_study(re, 0, &errptr); 
    28502856        if (errptr != NULL) { 
    2851           mush_free((Malloc_t) re, "pcre"); 
     2857          mush_free(re, "pcre"); 
    28522858          safe_str(T("#-1 REGEXP ERROR: "), buff, bp); 
    28532859          safe_str(errptr, buff, bp); 
     
    28602866          add_check("pcre.extra"); 
    28612867      } 
     2868      if (study) { 
     2869        extra = study; 
     2870        set_match_limit(extra); 
     2871      } else 
     2872        extra = default_match_limit(); 
     2873 
    28622874      search = 0; 
    28632875      /* Do all the searches and replaces we can */ 
    28642876      do { 
    28652877        subpatterns = 
    2866           pcre_exec(re, study, orig->text, orig->len, search, 0, offsets, 99); 
     2878          pcre_exec(re, extra, orig->text, orig->len, search, 0, offsets, 99); 
    28672879        if (subpatterns >= 0) { 
    28682880          /* We have a match */ 
     
    29012913        } 
    29022914      } while (subpatterns >= 0 && all); 
    2903       mush_free((Malloc_t) re, "pcre"); 
     2915      mush_free(re, "pcre"); 
    29042916      if (study != NULL) 
    2905         mush_free((Malloc_t) study, "pcre.extra"); 
     2917        mush_free(study, "pcre.extra"); 
    29062918    } 
    29072919    safe_ansi_string(orig, 0, orig->len, buff, bp); 
     
    29322944  char *qregs[NUMQ], *holder[NUMQ]; 
    29332945  pcre *re; 
     2946  pcre_extra *extra; 
    29342947  const char *errptr; 
    29352948  int erroffset; 
     
    29652978  } 
    29662979  add_check("pcre"); 
    2967   subpatterns = pcre_exec(re, NULL, txt, arglens[0], 0, 0, offsets, 99); 
     2980  extra = default_match_limit(); 
     2981 
     2982  subpatterns = pcre_exec(re, extra, txt, arglens[0], 0, 0, offsets, 99); 
    29682983  safe_integer(subpatterns >= 0, buff, bp); 
    29692984 
     
    30503065  } 
    30513066  for (i = 0; i < nqregs; i++) { 
    3052     mush_free((Malloc_t) holder[i], "regmatch"); 
    3053   } 
    3054   mush_free((Malloc_t) re, "pcre"); 
     3067    mush_free(holder[i], "regmatch"); 
     3068  } 
     3069  mush_free(re, "pcre"); 
    30553070  free_ansi_string(as); 
    30563071} 
     
    30743089  int erroffset; 
    30753090  int flags = 0; 
    3076  
     3091  bool free_study; 
    30773092  dbref it = match_thing(executor, args[0]); 
     3093 
    30783094  reharg.first = 0; 
    30793095  if (it == NOTHING || it == AMBIGUOUS) { 
     
    31103126    return; 
    31113127  } 
    3112   if (reharg.study) 
     3128  if (reharg.study) { 
    31133129    add_check("pcre.extra"); 
    3114  
     3130    free_study = true; 
     3131    set_match_limit(reharg.study); 
     3132  } else { 
     3133    free_study = false; 
     3134    reharg.study = default_match_limit(); 
     3135  } 
     3136       
    31153137  reharg.buff = buff; 
    31163138  reharg.bp = bp; 
     
    31183140  atr_iter_get(executor, it, args[1], 0, regrep_helper, (void *) &reharg); 
    31193141  mush_free(reharg.re, "pcre"); 
    3120   if (reharg.study) 
     3142  if (free_study) 
    31213143    mush_free(reharg.study, "pcre.extra"); 
    31223144} 
     
    31543176  size_t rlen; 
    31553177  pcre *re; 
    3156   pcre_extra *study
     3178  pcre_extra *study, *extra
    31573179  const char *errptr; 
    31583180  int erroffset; 
     
    31953217    return; 
    31963218  } 
    3197   if (study) 
     3219  if (study) { 
    31983220    add_check("pcre.extra"); 
     3221    extra = study; 
     3222    set_match_limit(extra); 
     3223  } else 
     3224    extra = default_match_limit(); 
    31993225 
    32003226  do { 
    32013227    r = remove_markup(split_token(&s, sep), &rlen); 
    3202     if (pcre_exec(re, study, r, rlen - 1, 0, 0, offsets, 99) >= 0) { 
     3228    if (pcre_exec(re, extra, r, rlen - 1, 0, 0, offsets, 99) >= 0) { 
    32033229      if (all && *bp != b) 
    32043230        safe_str(osep, buff, bp); 
     
    32093235  } while (s); 
    32103236 
    3211   mush_free((Malloc_t) re, "pcre"); 
     3237  mush_free(re, "pcre"); 
    32123238  if (study) 
    3213     mush_free((Malloc_t) study, "pcre.extra"); 
    3214 } 
     3239    mush_free(study, "pcre.extra"); 
     3240} 
  • 1.8.3/branches/devel/src/parse.c

    r1143 r1145  
    269269    re = pcre_compile("^#-?\\d+(?::\\d+)?$", 0, &errptr, &erroffset, NULL); 
    270270  val = remove_markup((const char *) str, &vlen); 
    271   return (pcre_exec(re, NULL, val, vlen - 1, 0, 0, NULL, 0) >= 0)
     271  return pcre_exec(re, NULL, val, vlen - 1, 0, 0, NULL, 0) >= 0
    272272} 
    273273 
  • 1.8.3/branches/devel/src/pcre.c

    r1143 r1145  
    4545 * 'isblank' as a variable (reported to Philip Hazel for pcre 4.5) */ 
    4646 
     47#include <string.h> 
    4748#include "config.h" 
     49#include "mypcre.h" 
    4850 
    4951/* Only use if a system libpcre isn't present. */ 
     
    5759#include <stdio.h> 
    5860#include <stdlib.h> 
    59 #include <string.h> 
    60 #include "mypcre.h" 
    6161#include "confmagic.h" 
    6262#undef min 
     
    92269226 
    92279227#endif /* !HAVE_PCRE */ 
     9228 
     9229/** Return a default pcre_extra pointer pointing to a static region 
     9230    set up to use a fairly low match-limit setting. 
     9231*/ 
     9232struct pcre_extra * 
     9233default_match_limit(void) 
     9234{ 
     9235  static struct pcre_extra ex; 
     9236  memset(&ex, 0, sizeof ex); 
     9237  set_match_limit(&ex); 
     9238  return &ex; 
     9239} 
     9240   
     9241 
     9242/** Set a low match-limit setting in an existing pcre_extra struct. */ 
     9243void 
     9244set_match_limit(struct pcre_extra *ex) 
     9245{ 
     9246  if (!ex) 
     9247    return; 
     9248  ex->flags |= PCRE_EXTRA_MATCH_LIMIT; 
     9249  ex->match_limit = PENN_MATCH_LIMIT; 
     9250} 
     9251 
  • 1.8.3/branches/devel/src/wild.c

    r1143 r1145  
    516516{ 
    517517  pcre *re; 
     518  pcre_extra *extra; 
    518519  size_t i; 
    519520  const char *errptr; 
     
    538539  add_check("pcre"); 
    539540  d = remove_markup(val, &delenn); 
     541  extra = default_match_limit(); 
    540542  /* 
    541543   * Now we try to match the pattern. The relevant fields will 
    542544   * automatically be filled in by this. 
    543545   */ 
    544   if ((subpatterns = pcre_exec(re, NULL, d, delenn - 1, 0, 0, offsets, 99)) 
     546  if ((subpatterns = pcre_exec(re, extra, d, delenn - 1, 0, 0, offsets, 99)) 
    545547      < 0) { 
    546548    mush_free(re, "pcre"); 
     
    592594{ 
    593595  pcre *re; 
     596  pcre_extra *extra; 
    594597  const char *sptr; 
    595598  size_t slen; 
     
    616619  add_check("pcre"); 
    617620  sptr = remove_markup(d, &slen); 
     621  extra = default_match_limit(); 
    618622  /* 
    619623   * Now we try to match the pattern. The relevant fields will 
    620624   * automatically be filled in by this. 
    621625   */ 
    622   r = pcre_exec(re, NULL, sptr, slen - 1, 0, 0, offsets, 99); 
     626  r = pcre_exec(re, extra, sptr, slen - 1, 0, 0, offsets, 99); 
    623627 
    624628  mush_free(re, "pcre"); 
     
    637641  int len; 
    638642  int offsets[99]; 
     643  pcre_extra *extra; 
    639644 
    640645  if (!re || !subj) 
     
    642647 
    643648  len = strlen(subj); 
    644  
    645   return pcre_exec(re, NULL, subj, len, 0, 0, offsets, 99) >= 0; 
    646  
     649  extra = default_match_limit(); 
     650  return pcre_exec(re, extra, subj, len, 0, 0, offsets, 99) >= 0; 
    647651} 
    648652