diff options
Diffstat (limited to 'regex')
-rw-r--r-- | regex/Makefile.am | 33 | ||||
-rw-r--r-- | regex/main.c | 6 | ||||
-rw-r--r-- | regex/my_regex.h | 4 | ||||
-rw-r--r-- | regex/regcomp.c | 15 | ||||
-rw-r--r-- | regex/regexec.c | 5 | ||||
-rw-r--r-- | regex/reginit.c | 6 |
6 files changed, 27 insertions, 42 deletions
diff --git a/regex/Makefile.am b/regex/Makefile.am deleted file mode 100644 index 0fd62a777f6..00000000000 --- a/regex/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (C) 2000-2003, 2005-2006 MySQL AB -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Library General Public -# License as published by the Free Software Foundation; version 2 -# of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Library General Public License for more details. -# -# You should have received a copy of the GNU Library General Public -# License along with this library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -# MA 02111-1307, USA - -INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -noinst_LIBRARIES = libregex.a -LDADD= libregex.a $(top_builddir)/strings/libmystrings.a -noinst_HEADERS = cclass.h cname.h regex2.h utils.h engine.c my_regex.h -libregex_a_SOURCES = regerror.c regcomp.c regexec.c regfree.c reginit.c -noinst_PROGRAMS = re -re_SOURCES = split.c debug.c main.c -re_LDFLAGS= @NOINST_LDFLAGS@ -EXTRA_DIST = tests CHANGES COPYRIGHT WHATSNEW regexp.c \ - debug.ih engine.ih main.ih regcomp.ih regerror.ih \ - regex.3 regex.7 CMakeLists.txt - -test: re tests - ./re < tests - ./re -el < tests - ./re -er < tests diff --git a/regex/main.c b/regex/main.c index e8277053382..f5b591907cf 100644 --- a/regex/main.c +++ b/regex/main.c @@ -17,7 +17,7 @@ regoff_t startoff = 0; regoff_t endoff = 0; -extern int split(char *string, char **fields, int nfields, const char *sep); +extern int split(char *string, char *fields[], int nfields, char *sep); extern void regprint(my_regex_t *r, FILE *d); /* @@ -145,7 +145,7 @@ FILE *in; inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */ if (debug) fprintf(stdout, "%d:\n", line); - nf = split(inbuf, f, MAXF, "\t\t"); + nf = split(inbuf, f, MAXF, (char*) "\t\t"); if (nf < 3) { fprintf(stderr, "bad input, line %d\n", line); exit(1); @@ -288,7 +288,7 @@ int opts; /* may not match f1 */ for (i = 1; i < NSHOULD; i++) should[i] = NULL; - nshould = split(f4, should+1, NSHOULD-1, ","); + nshould = split(f4, should+1, NSHOULD-1, (char*) ","); if (nshould == 0) { nshould = 1; should[1] = (char*) ""; diff --git a/regex/my_regex.h b/regex/my_regex.h index 0d1cedf5430..30896e29b91 100644 --- a/regex/my_regex.h +++ b/regex/my_regex.h @@ -28,6 +28,7 @@ typedef struct { /* === regcomp.c === */ +typedef int (*my_regex_stack_check_t)(); extern int my_regcomp(my_regex_t *, const char *, int, CHARSET_INFO *charset); #define REG_BASIC 0000 #define REG_EXTENDED 0001 @@ -76,7 +77,8 @@ extern void my_regfree(my_regex_t *); /* === reginit.c === */ -extern void my_regex_init(CHARSET_INFO *cs); /* Should be called for multithread progs */ +/* Should be called for multithread progs */ +extern void my_regex_init(CHARSET_INFO *cs, my_regex_stack_check_t func); extern void my_regex_end(void); /* If one wants a clean end */ #ifdef __cplusplus diff --git a/regex/regcomp.c b/regex/regcomp.c index b41a1ae6da9..6e2d2511fc1 100644 --- a/regex/regcomp.c +++ b/regex/regcomp.c @@ -31,6 +31,9 @@ struct parse { CHARSET_INFO *charset; /* for ctype things */ }; +/* Check if there is enough stack space for recursion. */ +my_regex_stack_check_t my_regex_enough_mem_in_stack= NULL; + #include "regcomp.ih" static char nuls[10]; /* place to point scanner in event of error */ @@ -117,7 +120,7 @@ CHARSET_INFO *charset; # define GOODFLAGS(f) ((f)&~REG_DUMP) #endif - my_regex_init(charset); /* Init cclass if neaded */ + my_regex_init(charset, NULL); /* Init cclass if neaded */ preg->charset=charset; cflags = GOODFLAGS(cflags); if ((cflags®_EXTENDED) && (cflags®_NOSPEC)) @@ -222,7 +225,15 @@ int stop; /* character this ERE should end at */ /* do a bunch of concatenated expressions */ conc = HERE(); while (MORE() && (c = PEEK()) != '|' && c != stop) - p_ere_exp(p); + { + if (my_regex_enough_mem_in_stack && + my_regex_enough_mem_in_stack()) + { + SETERROR(REG_ESPACE); + return; + } + p_ere_exp(p); + } if(REQUIRE(HERE() != conc, REG_EMPTY)) {}/* require nonempty */ if (!EAT('|')) diff --git a/regex/regexec.c b/regex/regexec.c index 338c1bfa7fe..c0d03335b41 100644 --- a/regex/regexec.c +++ b/regex/regexec.c @@ -117,6 +117,7 @@ size_t nmatch; my_regmatch_t pmatch[]; int eflags; { + char *pstr = (char *) str; register struct re_guts *g = preg->re_g; #ifdef REDEBUG # define GOODFLAGS(f) (f) @@ -133,7 +134,7 @@ int eflags; if ((size_t) g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE)) - return(smatcher(preg->charset, g, (char *)str, nmatch, pmatch, eflags)); + return(smatcher(preg->charset, g, pstr, nmatch, pmatch, eflags)); else - return(lmatcher(preg->charset, g, (char *)str, nmatch, pmatch, eflags)); + return(lmatcher(preg->charset, g, pstr, nmatch, pmatch, eflags)); } diff --git a/regex/reginit.c b/regex/reginit.c index 5980de24030..3d2cd64d1e7 100644 --- a/regex/reginit.c +++ b/regex/reginit.c @@ -4,10 +4,12 @@ #include <m_ctype.h> #include <m_string.h> #include "cclass.h" +#include "my_regex.h" static my_bool regex_inited=0; +extern my_regex_stack_check_t my_regex_enough_mem_in_stack; -void my_regex_init(CHARSET_INFO *cs) +void my_regex_init(CHARSET_INFO *cs, my_regex_stack_check_t func) { char buff[CCLASS_LAST][256]; int count[CCLASS_LAST]; @@ -16,6 +18,7 @@ void my_regex_init(CHARSET_INFO *cs) if (!regex_inited) { regex_inited=1; + my_regex_enough_mem_in_stack= func; bzero((uchar*) &count,sizeof(count)); for (i=1 ; i<= 255; i++) @@ -74,6 +77,7 @@ void my_regex_end() int i; for (i=0; i < CCLASS_LAST ; i++) free((char*) cclasses[i].chars); + my_regex_enough_mem_in_stack= NULL; regex_inited=0; } } |