Skip to content

Commit 602b5e4

Browse files
grooverdanvuvova
authored andcommitted
WIP: global readonly variable pcre_frame_size
1 parent b30311e commit 602b5e4

File tree

7 files changed

+33
-1
lines changed

7 files changed

+33
-1
lines changed

include/my_sys.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ extern void (*fatal_error_handler_hook)(uint my_err, const char *str,
227227
myf MyFlags);
228228
extern uint my_file_limit;
229229
extern ulonglong my_thread_stack_size;
230+
#ifndef EMBEDDED_LIBRARY
231+
extern ulonglong my_pcre_frame_size;
232+
#endif
230233
extern int sf_leaking_memory; /* set to 1 to disable memleak detection */
231234

232235
extern void (*proc_info_hook)(void *, const PSI_stage_info *, PSI_stage_info *,

mysys/my_init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ my_bool my_init_done= 0;
4545
uintmysys_usage_id= 0; /* Incremented for each my_init() */
4646

4747
ulonglong my_thread_stack_size= (sizeof(void*) <= 4)? 65536: ((256-16)*1024);
48+
/* http://pcre.org/original/doc/html/pcrestack.html - replaced by init_pcre value */
49+
ulonglong my_pcre_frame_size= 640 + 16;
4850

4951
static ulong atoi_octal(const char *str)
5052
{

sql/item_cmpfunc.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "thr_malloc.h" /* sql_calloc */
2727
#include "item_func.h" /* Item_int_func, Item_bool_func */
28+
long check_stack_available(long margin, uchar *dummy);
2829
#define PCRE_STATIC 1 /* Important on Windows */
2930
#include "pcre.h" /* pcre header file */
3031

@@ -1576,8 +1577,13 @@ class Regexp_processor_pcre
15761577
m_library_charset(&my_charset_utf8_general_ci),
15771578
m_subpatterns_needed(0)
15781579
{
1580+
#ifndef EMBEDDED_LIBRARY
1581+
uchar dummy;
15791582
m_pcre_extra.flags= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
1580-
m_pcre_extra.match_limit_recursion= 100L;
1583+
m_pcre_extra.match_limit_recursion= check_stack_available(100, &dummy) / my_pcre_frame_size;
1584+
#else
1585+
m_pcre_extra.flags= 0L;
1586+
#endif
15811587
}
15821588
int default_regex_flags();
15831589
void init(CHARSET_INFO *data_charset, int extra_flags, uint nsubpatterns)

sql/mysqld.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#include "sp_rcontext.h"
101101
#include "sp_cache.h"
102102
#include "sql_reload.h" // reload_acl_and_cache
103+
#include "pcre.h"
103104

104105
#ifdef HAVE_POLL_H
105106
#include <poll.h>
@@ -3503,6 +3504,9 @@ static void init_pcre()
35033504
pcre_free= pcre_stack_free= my_str_free_mysqld;
35043505
#ifndef EMBEDDED_LIBRARY
35053506
pcre_stack_guard= check_enough_stack_size_slow;
3507+
/* my_pcre_frame_size= -pcre_exec(NULL, NULL, NULL, -999, -999, 0, NULL, 0) + 16;
3508+
http://pcre.org/original/doc/html/pcrestack.html has reason for + 16
3509+
my_pcre_frame_size= -pcre_match(NULL, NULL, NULL, 0, NULL, NULL, 0) + 16; */
35063510
#endif
35073511
}
35083512

sql/sql_parse.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6208,6 +6208,14 @@ bool check_stack_overrun(THD *thd, long margin,
62086208
return 0;
62096209
}
62106210

6211+
long check_stack_available(long margin,
6212+
uchar *buf __attribute__((unused)))
6213+
{
6214+
long stack_top;
6215+
DBUG_ASSERT(current_thd);
6216+
return my_thread_stack_size - margin \
6217+
- used_stack(current_thd->thread_stack,(char*) &stack_top);
6218+
}
62116219

62126220
#define MY_YACC_INIT 1000// Start with big alloc
62136221
#define MY_YACC_MAX 32000// Because of 'short'

sql/sql_parse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ bool check_simple_select();
134134
Item *normalize_cond(Item *cond);
135135
Item *negate_expression(THD *thd, Item *expr);
136136
bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
137+
long check_stack_available(long margin, uchar *dummy);
137138

138139
/* Variables */
139140

sql/sys_vars.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,6 +2493,14 @@ static Sys_var_ulonglong Sys_thread_stack(
24932493
VALID_RANGE(128*1024, ULONGLONG_MAX), DEFAULT(DEFAULT_THREAD_STACK),
24942494
BLOCK_SIZE(1024));
24952495

2496+
#ifndef EMBEDDED_LIBRARY
2497+
static Sys_var_ulonglong Sys_my_pcre_frame_size(
2498+
"pcre_frame_size", "Frame size for pcre_recursion",
2499+
GLOBAL_VAR(my_pcre_frame_size), NO_CMD_LINE,
2500+
VALID_RANGE(500,1024), DEFAULT(640 + 16), 1, NO_MUTEX_GUARD,
2501+
NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0));
2502+
#endif
2503+
24962504
static Sys_var_charptr Sys_tmpdir(
24972505
"tmpdir", "Path for temporary files. Several paths may "
24982506
"be specified, separated by a "

0 commit comments

Comments
 (0)