diff options
author | Sergei Golubchik <serg@mariadb.org> | 2020-01-14 20:55:20 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2020-01-16 18:13:55 +0100 |
commit | fc5a6a28f7f5580b78ca51e781ae7add5cc83ac7 (patch) | |
tree | 98a398eebb854e034d7646622c9d68ab97f46e16 /sql/item_cmpfunc.cc | |
parent | ff5a528f260ea81e5ef06f4fd36c3d179e91fbd9 (diff) | |
download | mariadb-git-fc5a6a28f7f5580b78ca51e781ae7add5cc83ac7.tar.gz |
compatibility with pcre2 < 10.30
* It uses stack a lot, limit the recursion depth like
we used to do for pcre.
* But don't do that for newer pcre2 that uses stack very little
(and doesn't support limiting recursion depth anyway).
* Fix tests to verify only that deep recursion doesn't crash, but
ignore results and warnings (which depend on pcre2 version)
* Also different pcre2 versions report different offset in error messages,
take that into account.
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r-- | sql/item_cmpfunc.cc | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index b6acbee37f9..4090c39e5e0 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -5898,9 +5898,18 @@ bool Regexp_processor_pcre::compile(String *pattern, bool send_error) if (!(pattern= convert_if_needed(pattern, &pattern_converter))) return true; + pcre2_compile_context *cctx= NULL; +#ifndef pcre2_set_depth_limit + // old pcre2 uses stack - put a limit on that (new pcre2 prefers heap) + cctx= pcre2_compile_context_create(NULL); + pcre2_set_compile_recursion_guard(cctx, [](uint32_t cur, void *end) -> int + { return available_stack_size(&cur, end) < STACK_MIN_SIZE; }, + current_thd->mysys_var->stack_ends_here); +#endif m_pcre= pcre2_compile((PCRE2_SPTR8) pattern->ptr(), pattern->length(), m_library_flags, - &pcreErrorNumber, &pcreErrorOffset, NULL); + &pcreErrorNumber, &pcreErrorOffset, cctx); + pcre2_compile_context_free(cctx); // NULL is ok here if (unlikely(m_pcre == NULL)) { @@ -5964,8 +5973,16 @@ int Regexp_processor_pcre::pcre_exec_with_warn(const pcre2_code *code, int length, int startoffset, int options) { + pcre2_match_context *mctx= NULL; +#ifndef pcre2_set_depth_limit + // old pcre2 uses stack - put a limit on that (new pcre2 prefers heap) + mctx= pcre2_match_context_create(NULL); + pcre2_set_recursion_limit(mctx, + available_stack_size(&mctx, current_thd->mysys_var->stack_ends_here)/544); +#endif int rc= pcre2_match(code, (PCRE2_SPTR8) subject, (PCRE2_SIZE) length, - (PCRE2_SIZE) startoffset, options, data, NULL); + (PCRE2_SIZE) startoffset, options, data, mctx); + pcre2_match_context_free(mctx); // NULL is ok here DBUG_EXECUTE_IF("pcre_exec_error_123", rc= -123;); if (unlikely(rc < PCRE2_ERROR_NOMATCH)) { |