diff options
author | Alexander Barkov <bar@mnogosearch.org> | 2013-10-02 11:58:29 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mnogosearch.org> | 2013-10-02 11:58:29 +0400 |
commit | fcf992ba4c0c6b796ba8108c5e1ef99be1d58459 (patch) | |
tree | 75d420c24224d5e9994acfc258a194ac81656c00 /pcre | |
parent | d83648f25ad74f6ea55cff01f124f3920adbb728 (diff) | |
download | mariadb-git-fcf992ba4c0c6b796ba8108c5e1ef99be1d58459.tar.gz |
MDEV-4425 REGEXP enhancements
Adding pcre_stack_guard to avoid crashes in pcre_compile()
on a long recursive patterns with parenthesizes:
SELECT a RLIKE '((((...((((x)))...))))';
Diffstat (limited to 'pcre')
-rw-r--r-- | pcre/pcre.h.in | 2 | ||||
-rw-r--r-- | pcre/pcre_compile.c | 6 | ||||
-rw-r--r-- | pcre/pcre_globals.c | 2 |
3 files changed, 10 insertions, 0 deletions
diff --git a/pcre/pcre.h.in b/pcre/pcre.h.in index d6766339090..9de72356285 100644 --- a/pcre/pcre.h.in +++ b/pcre/pcre.h.in @@ -486,6 +486,7 @@ PCRE_EXP_DECL void (*pcre_free)(void *); PCRE_EXP_DECL void *(*pcre_stack_malloc)(size_t); PCRE_EXP_DECL void (*pcre_stack_free)(void *); PCRE_EXP_DECL int (*pcre_callout)(pcre_callout_block *); +PCRE_EXP_DECL int (*pcre_stack_guard)(void); PCRE_EXP_DECL void *(*pcre16_malloc)(size_t); PCRE_EXP_DECL void (*pcre16_free)(void *); @@ -504,6 +505,7 @@ PCRE_EXP_DECL void pcre_free(void *); PCRE_EXP_DECL void *pcre_stack_malloc(size_t); PCRE_EXP_DECL void pcre_stack_free(void *); PCRE_EXP_DECL int pcre_callout(pcre_callout_block *); +PCRE_EXP_DECL int pcre_stack_guard(void); PCRE_EXP_DECL void *pcre16_malloc(size_t); PCRE_EXP_DECL void pcre16_free(void *); diff --git a/pcre/pcre_compile.c b/pcre/pcre_compile.c index 1f7bdb40b19..0ebb3f168f1 100644 --- a/pcre/pcre_compile.c +++ b/pcre/pcre_compile.c @@ -7107,6 +7107,12 @@ unsigned int orig_bracount; unsigned int max_bracount; branch_chain bc; +if (pcre_stack_guard && pcre_stack_guard()) +{ + *errorcodeptr= ERR23; + return FALSE; +} + bc.outer = bcptr; bc.current_branch = code; diff --git a/pcre/pcre_globals.c b/pcre/pcre_globals.c index 36e6ddb3a89..3f878144a27 100644 --- a/pcre/pcre_globals.c +++ b/pcre/pcre_globals.c @@ -72,6 +72,7 @@ PCRE_EXP_DATA_DEFN void (*PUBL(free))(void *) = LocalPcreFree; PCRE_EXP_DATA_DEFN void *(*PUBL(stack_malloc))(size_t) = LocalPcreMalloc; PCRE_EXP_DATA_DEFN void (*PUBL(stack_free))(void *) = LocalPcreFree; PCRE_EXP_DATA_DEFN int (*PUBL(callout))(PUBL(callout_block) *) = NULL; +PCRE_EXP_DATA_DEFN int (*PUBL(stack_guard))(void) = NULL; #elif !defined VPCOMPAT PCRE_EXP_DATA_DEFN void *(*PUBL(malloc))(size_t) = malloc; @@ -79,6 +80,7 @@ PCRE_EXP_DATA_DEFN void (*PUBL(free))(void *) = free; PCRE_EXP_DATA_DEFN void *(*PUBL(stack_malloc))(size_t) = malloc; PCRE_EXP_DATA_DEFN void (*PUBL(stack_free))(void *) = free; PCRE_EXP_DATA_DEFN int (*PUBL(callout))(PUBL(callout_block) *) = NULL; +PCRE_EXP_DATA_DEFN int (*PUBL(stack_guard))(void) = NULL; #endif /* End of pcre_globals.c */ |