List:Commits« Previous MessageNext Message »
From:Dmitry Shulga Date:October 21 2010 8:41am
Subject:bzr commit into mysql-5.5-runtime branch (Dmitry.Shulga:3170) Bug#45445
View as plain text  
#At file:///Users/shulga/projects/mysql/5.5-runtime-bug45445/ based on revid:jon.hauglid@stripped

 3170 Dmitry Shulga	2010-10-21
      Fixed bug#45445 - cannot execute procedures with thread_stack
      set to 128k.
     @ sql/sp.cc
        Added checking for stack overrun at functions
        db_load_routine/sp_find_routine.
     @ sql/sp_head.cc
        sp_head::execute() modified: pass constant value STACK_MIN_SIZE
        instead of 8 * STACK_MIN_SIZE  as second argument value
        in call to check_stack_overrun. Added checking for stack overrun
        at functions sp_lex_keeper::reset_lex_and_exec_core/sp_instr_stmt::execute.
     @ sql/sql_parse.cc
        check_stack_overrun modified: allocate buffer for error message
        at heap instead of stack.
        parse_sql modified: added call to check_stack_overrun() before
        parsing of sql statement.

    modified:
      sql/sp.cc
      sql/sp_head.cc
      sql/sql_parse.cc
=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2010-10-07 16:01:17 +0000
+++ b/sql/sp.cc	2010-10-21 08:41:13 +0000
@@ -779,6 +779,9 @@ db_load_routine(THD *thd, int type, sp_n
 
   int ret= 0;
 
+  if (check_stack_overrun(thd, STACK_MIN_SIZE, (uchar*)&ret))
+    return TRUE;
+
   thd->lex= &newlex;
   newlex.current_select= NULL;
 
@@ -1505,6 +1508,9 @@ sp_find_routine(THD *thd, int type, sp_n
                        (int) name->m_name.length, name->m_name.str,
                        type, cache_only));
 
+  if (check_stack_overrun(thd, STACK_MIN_SIZE, (uchar*)&depth))
+    return NULL;
+
   if ((sp= sp_cache_lookup(cp, name)))
   {
     ulong level;

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2010-10-13 09:34:02 +0000
+++ b/sql/sp_head.cc	2010-10-21 08:41:13 +0000
@@ -1233,11 +1233,8 @@ sp_head::execute(THD *thd)
     The same with db_load_routine() required circa 7k bytes and
     14k bytes accordingly. Hence, here we book the stack with some
     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);
 
   /* init per-instruction memroot */
@@ -2902,6 +2899,9 @@ sp_lex_keeper::reset_lex_and_exec_core(T
     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;
+  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;
   DBUG_ASSERT(!thd->derived_tables);
   DBUG_ASSERT(thd->change_list.is_empty());
@@ -3057,6 +3057,9 @@ sp_instr_stmt::execute(THD *thd, uint *n
   DBUG_ENTER("sp_instr_stmt::execute");
   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_length= thd->query_length();
 #if defined(ENABLED_PROFILING)

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2010-10-19 09:26:45 +0000
+++ b/sql/sql_parse.cc	2010-10-21 08:41:13 +0000
@@ -5118,10 +5118,17 @@ bool check_stack_overrun(THD *thd, long 
   if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >=
       (long) (my_thread_stack_size - margin))
   {
-    char ebuff[MYSQL_ERRMSG_SIZE];
-    my_snprintf(ebuff, sizeof(ebuff), ER(ER_STACK_OVERRUN_NEED_MORE),
-                stack_used, my_thread_stack_size, margin);
-    my_message(ER_STACK_OVERRUN_NEED_MORE, ebuff, MYF(ME_FATALERROR));
+    /*
+      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);
+      my_message(ER_STACK_OVERRUN_NEED_MORE, ebuff, MYF(ME_FATALERROR));
+      delete [] ebuff;
+    }
     return 1;
   }
 #ifndef DBUG_OFF
@@ -7210,6 +7217,9 @@ bool parse_sql(THD *thd,
 
   Object_creation_ctx *backup_ctx= NULL;
 
+  if (check_stack_overrun(thd, 2 * STACK_MIN_SIZE, (uchar*)&backup_ctx))
+    return TRUE;
+
   if (creation_ctx)
     backup_ctx= creation_ctx->set_n_backup(thd);
 


Attachment: [text/bzr-bundle] bzr/dmitry.shulga@sun.com-20101021084113-8o39fxmriqrurkhg.bundle
Thread
bzr commit into mysql-5.5-runtime branch (Dmitry.Shulga:3170) Bug#45445Dmitry Shulga21 Oct