Commit 3d9cddab authored by Dmitry Shulga's avatar Dmitry Shulga

Fixed bug#45445 - cannot execute procedures with thread_stack

set to 128k.
parent 5ea471bd
...@@ -779,6 +779,9 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp, ...@@ -779,6 +779,9 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
int ret= 0; int ret= 0;
if (check_stack_overrun(thd, STACK_MIN_SIZE, (uchar*)&ret))
return TRUE;
thd->lex= &newlex; thd->lex= &newlex;
newlex.current_select= NULL; newlex.current_select= NULL;
...@@ -1505,6 +1508,9 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, ...@@ -1505,6 +1508,9 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp,
(int) name->m_name.length, name->m_name.str, (int) name->m_name.length, name->m_name.str,
type, cache_only)); type, cache_only));
if (check_stack_overrun(thd, STACK_MIN_SIZE, (uchar*)&depth))
return NULL;
if ((sp= sp_cache_lookup(cp, name))) if ((sp= sp_cache_lookup(cp, name)))
{ {
ulong level; ulong level;
......
...@@ -1233,11 +1233,8 @@ sp_head::execute(THD *thd) ...@@ -1233,11 +1233,8 @@ sp_head::execute(THD *thd)
The same with db_load_routine() required circa 7k bytes and The same with db_load_routine() required circa 7k bytes and
14k bytes accordingly. Hence, here we book the stack with some 14k bytes accordingly. Hence, here we book the stack with some
reasonable margin. reasonable margin.
Reverting back to 8 * STACK_MIN_SIZE until further fix.
8 * STACK_MIN_SIZE is required on some exotic platforms.
*/ */
if (check_stack_overrun(thd, 8 * STACK_MIN_SIZE, (uchar*)&old_packet)) if (check_stack_overrun(thd, STACK_MIN_SIZE, (uchar*)&old_packet))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
/* init per-instruction memroot */ /* init per-instruction memroot */
...@@ -2902,6 +2899,9 @@ sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp, ...@@ -2902,6 +2899,9 @@ sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp,
It's merged with the saved parent's value at the exit of this func. It's merged with the saved parent's value at the exit of this func.
*/ */
bool parent_modified_non_trans_table= thd->transaction.stmt.modified_non_trans_table; bool parent_modified_non_trans_table= thd->transaction.stmt.modified_non_trans_table;
if (check_stack_overrun(thd, STACK_MIN_SIZE, (uchar*)&parent_modified_non_trans_table))
DBUG_RETURN(TRUE);
thd->transaction.stmt.modified_non_trans_table= FALSE; thd->transaction.stmt.modified_non_trans_table= FALSE;
DBUG_ASSERT(!thd->derived_tables); DBUG_ASSERT(!thd->derived_tables);
DBUG_ASSERT(thd->change_list.is_empty()); DBUG_ASSERT(thd->change_list.is_empty());
...@@ -3057,6 +3057,9 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) ...@@ -3057,6 +3057,9 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
DBUG_ENTER("sp_instr_stmt::execute"); DBUG_ENTER("sp_instr_stmt::execute");
DBUG_PRINT("info", ("command: %d", m_lex_keeper.sql_command())); DBUG_PRINT("info", ("command: %d", m_lex_keeper.sql_command()));
if (check_stack_overrun(thd, STACK_MIN_SIZE, (uchar*)&res))
DBUG_RETURN(TRUE);
query= thd->query(); query= thd->query();
query_length= thd->query_length(); query_length= thd->query_length();
#if defined(ENABLED_PROFILING) #if defined(ENABLED_PROFILING)
......
...@@ -5118,10 +5118,17 @@ bool check_stack_overrun(THD *thd, long margin, ...@@ -5118,10 +5118,17 @@ bool check_stack_overrun(THD *thd, long margin,
if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >= if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >=
(long) (my_thread_stack_size - margin)) (long) (my_thread_stack_size - margin))
{ {
char ebuff[MYSQL_ERRMSG_SIZE]; /*
my_snprintf(ebuff, sizeof(ebuff), ER(ER_STACK_OVERRUN_NEED_MORE), Do not use stack for the message buffer to ensure correct
behaviour in cases we have close to no stack left.
*/
char* ebuff= new char[MYSQL_ERRMSG_SIZE];
if (ebuff) {
my_snprintf(ebuff, MYSQL_ERRMSG_SIZE, ER(ER_STACK_OVERRUN_NEED_MORE),
stack_used, my_thread_stack_size, margin); stack_used, my_thread_stack_size, margin);
my_message(ER_STACK_OVERRUN_NEED_MORE, ebuff, MYF(ME_FATALERROR)); my_message(ER_STACK_OVERRUN_NEED_MORE, ebuff, MYF(ME_FATALERROR));
delete [] ebuff;
}
return 1; return 1;
} }
#ifndef DBUG_OFF #ifndef DBUG_OFF
...@@ -7210,6 +7217,9 @@ bool parse_sql(THD *thd, ...@@ -7210,6 +7217,9 @@ bool parse_sql(THD *thd,
Object_creation_ctx *backup_ctx= NULL; Object_creation_ctx *backup_ctx= NULL;
if (check_stack_overrun(thd, 2 * STACK_MIN_SIZE, (uchar*)&backup_ctx))
return TRUE;
if (creation_ctx) if (creation_ctx)
backup_ctx= creation_ctx->set_n_backup(thd); backup_ctx= creation_ctx->set_n_backup(thd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment