mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Fixed bug#58026 - massive recursion and crash in regular expression
handling. The problem was that parsing of nested regular expression involved recursive calls. Such recursion didn't take into account the amount of available stack space, which ended up leading to stack overflow crashes.
This commit is contained in:
@@ -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('|'))
|
||||
|
||||
Reference in New Issue
Block a user