diff options
Diffstat (limited to 'src/libregexp/regcomp.c')
-rw-r--r-- | src/libregexp/regcomp.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/libregexp/regcomp.c b/src/libregexp/regcomp.c index 0dabd4f0..09678755 100644 --- a/src/libregexp/regcomp.c +++ b/src/libregexp/regcomp.c @@ -15,6 +15,12 @@ struct Node Reinst* last; }Node; +/* max character classes per program is nelem(reprog->class) */ +static Reprog *reprog; + +/* max rune ranges per character class is nelem(classp->spans)/2 */ +#define NCCRUNE nelem(classp->spans) + #define NSTACK 20 static Node andstack[NSTACK]; static Node *andp; @@ -321,8 +327,8 @@ dump(Reprog *pp) static Reclass* newclass(void) { - if(nclass >= NCLASS) - regerr2("too many character classes; limit", NCLASS+'0'); + if(nclass >= nelem(reprog->class)) + rcerror("too many character classes; increase Reprog.class size"); return &(classp[nclass++]); } @@ -407,7 +413,7 @@ bldcclass(void) } /* parse class into a set of spans */ - for(; ep<&r[NCCRUNE];){ + while(ep < &r[NCCRUNE-1]){ if(rune == 0){ rcerror("malformed '[]'"); return 0; @@ -431,6 +437,10 @@ bldcclass(void) } quoted = nextc(&rune); } + if(ep >= &r[NCCRUNE-1]) { + rcerror("char class too large; increase Reclass.spans size"); + return 0; + } /* sort on span start */ for(p = r; p < ep; p += 2){ @@ -454,9 +464,10 @@ bldcclass(void) np[0] = *p++; np[1] = *p++; for(; p < ep; p += 2) - if(p[0] <= np[1]){ - if(p[1] > np[1]) - np[1] = p[1]; + /* overlapping or adjacent ranges? */ + if(p[0] <= np[1] + 1){ + if(p[1] >= np[1]) + np[1] = p[1]; /* coalesce */ } else { np += 2; np[0] = p[0]; |