From 2e113adab37ace8df172e2cbea11e8abcfdec267 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 May 2005 12:06:15 +0200 Subject: [PATCH] Post-review fixes of BUG#9937: Crash on call to stored procedure. sql/item_cmpfunc.cc: Put the buff parameter back in check_stack_overrun(). sql/item_func.cc: Put the buff parameter back in check_stack_overrun(). sql/item_subselect.cc: Put the buff parameter back in check_stack_overrun(). sql/mysql_priv.h: Put the buff parameter back in check_stack_overrun(). sql/mysqld.cc: Style fixes. sql/sp_head.cc: Put the buff parameter back in check_stack_overrun(). sql/sql_parse.cc: Put the buff parameter back in check_stack_overrun(), and added comment explaining the purpose. sql/table.cc: Put the buff parameter back in check_stack_overrun(). --- sql/item_cmpfunc.cc | 2 +- sql/item_func.cc | 10 ++++++++-- sql/item_subselect.cc | 2 +- sql/mysql_priv.h | 4 ++-- sql/mysqld.cc | 12 ++++++++---- sql/sp_head.cc | 2 +- sql/sql_parse.cc | 9 ++++++++- sql/table.cc | 2 +- 8 files changed, 30 insertions(+), 13 deletions(-) diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 378d3645caf..66f0bf9c395 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -2321,7 +2321,7 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) */ and_tables_cache= ~(table_map) 0; - if (check_stack_overrun(thd, STACK_MIN_SIZE)) + if (check_stack_overrun(thd, STACK_MIN_SIZE, buff)) return TRUE; // Fatal error flag is set! /* The following optimization reduces the depth of an AND-OR tree. diff --git a/sql/item_func.cc b/sql/item_func.cc index 13c9aa92d6e..47dffa679e9 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -293,11 +293,14 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) { DBUG_ASSERT(fixed == 0); Item **arg,**arg_end; +#ifndef EMBEDDED_LIBRARY // Avoid compiler warning + char buff[STACK_BUFF_ALLOC]; // Max argument in function +#endif used_tables_cache= not_null_tables_cache= 0; const_item_cache=1; - if (check_stack_overrun(thd, STACK_MIN_SIZE+STACK_BUFF_ALLOC)) + if (check_stack_overrun(thd, STACK_MIN_SIZE, buff)) return TRUE; // Fatal error if flag is set! if (arg_count) { // Print purify happy @@ -2564,9 +2567,12 @@ bool udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, uint arg_count, Item **arguments) { +#ifndef EMBEDDED_LIBRARY // Avoid compiler warning + char buff[STACK_BUFF_ALLOC]; // Max argument in function +#endif DBUG_ENTER("Item_udf_func::fix_fields"); - if (check_stack_overrun(thd, STACK_MIN_SIZE+STACK_BUFF_ALLOC)) + if (check_stack_overrun(thd, STACK_MIN_SIZE, buff)) DBUG_RETURN(TRUE); // Fatal error flag is set! udf_func *tmp_udf=find_udf(u_d->name.str,(uint) u_d->name.length,1); diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 328bc75757b..5c26f3c079c 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -138,7 +138,7 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref) DBUG_ASSERT(fixed == 0); engine->set_thd((thd= thd_param)); - if (check_stack_overrun(thd, STACK_MIN_SIZE)) + if (check_stack_overrun(thd, STACK_MIN_SIZE, (gptr)&res)) return TRUE; res= engine->prepare(); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index e9a325f1fa7..eb7fa68e8e8 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1429,11 +1429,11 @@ inline int hexchar_to_int(char c) #ifndef EMBEDDED_LIBRARY extern "C" void unireg_abort(int exit_code); void kill_delayed_threads(void); -bool check_stack_overrun(THD *thd, long margin); +bool check_stack_overrun(THD *thd, long margin, char *dummy); #else #define unireg_abort(exit_code) DBUG_RETURN(exit_code) inline void kill_delayed_threads(void) {} -#define check_stack_overrun(A, B) 0 +#define check_stack_overrun(A, B, C) 0 #endif #endif /* MYSQL_CLIENT */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e3a74d378fa..5479a5466f0 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2091,8 +2091,10 @@ static void start_signal_handler(void) if (!(opt_specialflag & SPECIAL_NO_PRIOR)) my_pthread_attr_setprio(&thr_attr,INTERRUPT_PRIOR); #if defined(__ia64__) || defined(__ia64) - /* Peculiar things with ia64 platforms - it seems we only have half the - stack size in reality, so we have to double it here */ + /* + Peculiar things with ia64 platforms - it seems we only have half the + stack size in reality, so we have to double it here + */ pthread_attr_setstacksize(&thr_attr,thread_stack*2); #else pthread_attr_setstacksize(&thr_attr,thread_stack); @@ -3018,8 +3020,10 @@ int main(int argc, char **argv) if (!(opt_specialflag & SPECIAL_NO_PRIOR)) my_pthread_setprio(pthread_self(),CONNECT_PRIOR); #if defined(__ia64__) || defined(__ia64) - /* Peculiar things with ia64 platforms - it seems we only have half the - stack size in reality, so we have to double it here */ + /* + Peculiar things with ia64 platforms - it seems we only have half the + stack size in reality, so we have to double it here + */ pthread_attr_setstacksize(&connection_attrib,thread_stack*2); #else pthread_attr_setstacksize(&connection_attrib,thread_stack); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 9d055d55f54..fcca1b51d1c 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -565,7 +565,7 @@ sp_head::execute(THD *thd) String old_packet; /* Use some extra margin for possible SP recursion and functions */ - if (check_stack_overrun(thd, 4*STACK_MIN_SIZE)) + if (check_stack_overrun(thd, 4*STACK_MIN_SIZE, olddb)) { DBUG_RETURN(-1); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7edd93f8d0d..e2746ffbdc8 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4986,7 +4986,14 @@ long max_stack_used; #endif #ifndef EMBEDDED_LIBRARY -bool check_stack_overrun(THD *thd, long margin) +/* + Note: The 'buf' parameter is necessary, even if it is unused here. + - fix_fields functions has a "dummy" buffer large enough for the + corresponding exec. (Thus we only have to check in fix_fields.) + - Passing to check_stack_overrun() prevents the compiler from removing it. + */ +bool check_stack_overrun(THD *thd, long margin, + char *buf __attribute__((unused))) { long stack_used; if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >= diff --git a/sql/table.cc b/sql/table.cc index bc31a38f24a..eb4dbe5a1f3 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1815,7 +1815,7 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds, bool res= FALSE; DBUG_ENTER("st_table_list::setup_ancestor"); - if (check_stack_overrun(thd, STACK_MIN_SIZE)) + if (check_stack_overrun(thd, STACK_MIN_SIZE, (char *)&res)) return TRUE; for (tbl= ancestor; tbl; tbl= tbl->next_local)