Commit accdff51 authored by unknown's avatar unknown
Browse files

Fixed BUG#11365: Stored Procedure: Crash on Procedure operation

  Two separate problems. A key buffer was too small in sp.cc for multi-byte
  fields, and the creation and fixing of mysql.proc in the scripts hadn't been
  updated with the correct character sets and collations (like the other
  system tables had).
  Note: No special test case, as the use of utf8 for mysql.proc will make
  any existing crash (if the buffer overrrun wasn't fixed).


mysql-test/r/sp-error.result:
  Updated test case for too long SP names (as the limit has increased with the use of utf8).
mysql-test/t/sp-error.test:
  Updated test case for too long SP names (as the limit has increased with the use of utf8).
scripts/mysql_create_system_tables.sh:
  Use utf8 for mysql.proc, just like for the other system tables.
scripts/mysql_fix_privilege_tables.sql:
  Use utf8 for mysql.proc, just like for the other system tables.
  (Some tabs also replaced by space)
sql/sp.cc:
  Use a larger key buffer for stored procedures to avoid stack overrun with multi-byte keys.
parent 7672befa
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -604,10 +604,10 @@ flush tables;
return 5;
end|
ERROR 0A000: FLUSH is not allowed in stored procedures
create procedure bug9529_90123456789012345678901234567890123456789012345678901234567890()
create procedure bug9529_90123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123()
begin
end|
ERROR 42000: Identifier name 'bug9529_90123456789012345678901234567890123456789012345678901234567890' is too long
ERROR 42000: Identifier name 'bug9529_90123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890' is too long
drop procedure if exists bug10969|
create procedure bug10969()
begin
+2 −2
Original line number Diff line number Diff line
@@ -874,9 +874,9 @@ end|
#
# BUG#9529: Stored Procedures: No Warning on truncation of procedure name
#           during creation.
#
# Note: When using utf8 for mysql.proc, this limit is much higher than before
--error ER_TOO_LONG_IDENT
create procedure bug9529_90123456789012345678901234567890123456789012345678901234567890()
create procedure bug9529_90123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123()
begin
end|

+7 −5
Original line number Diff line number Diff line
@@ -669,7 +669,7 @@ fi
if test ! -f $mdata/proc.frm
then
  c_p="$c_p CREATE TABLE proc ("
  c_p="$c_p   db                char(64) binary DEFAULT '' NOT NULL,"
  c_p="$c_p   db                char(64) collate utf8_bin DEFAULT '' NOT NULL,"
  c_p="$c_p   name              char(64) DEFAULT '' NOT NULL,"
  c_p="$c_p   type              enum('FUNCTION','PROCEDURE') NOT NULL,"
  c_p="$c_p   specific_name     char(64) DEFAULT '' NOT NULL,"
@@ -684,7 +684,7 @@ then
  c_p="$c_p   param_list        blob DEFAULT '' NOT NULL,"
  c_p="$c_p   returns           char(64) DEFAULT '' NOT NULL,"
  c_p="$c_p   body              blob DEFAULT '' NOT NULL,"
  c_p="$c_p   definer           char(77) binary DEFAULT '' NOT NULL,"
  c_p="$c_p   definer           char(77) collate utf8_bin DEFAULT '' NOT NULL,"
  c_p="$c_p   created           timestamp,"
  c_p="$c_p   modified          timestamp,"
  c_p="$c_p   sql_mode          set("
@@ -718,10 +718,12 @@ then
  c_p="$c_p                         'TRADITIONAL',"
  c_p="$c_p                         'NO_AUTO_CREATE_USER',"
  c_p="$c_p                         'HIGH_NOT_PRECEDENCE'"
  c_p="$c_p                     ) DEFAULT 0 NOT NULL,"
  c_p="$c_p   comment           char(64) binary DEFAULT '' NOT NULL,"
  c_p="$c_p                     ) DEFAULT '' NOT NULL,"
  c_p="$c_p   comment           char(64) collate utf8_bin DEFAULT '' NOT NULL,"
  c_p="$c_p   PRIMARY KEY (db,name,type)"
  c_p="$c_p ) comment='Stored Procedures';"
  c_p="$c_p ) engine=MyISAM"
  c_p="$c_p character set utf8"
  c_p="$c_p comment='Stored Procedures';"
fi

cat << END_OF_DATA
+29 −16
Original line number Diff line number Diff line
@@ -412,7 +412,7 @@ PRIMARY KEY TranTime (Transition_time)
#

CREATE TABLE IF NOT EXISTS proc (
  db                char(64) binary DEFAULT '' NOT NULL,
  db                char(64) collate utf8_bin DEFAULT '' NOT NULL,
  name              char(64) DEFAULT '' NOT NULL,
  type              enum('FUNCTION','PROCEDURE') NOT NULL,
  specific_name     char(64) DEFAULT '' NOT NULL,
@@ -427,7 +427,7 @@ CREATE TABLE IF NOT EXISTS proc (
  param_list        blob DEFAULT '' NOT NULL,
  returns           char(64) DEFAULT '' NOT NULL,
  body              blob DEFAULT '' NOT NULL,
  definer           char(77) binary DEFAULT '' NOT NULL,
  definer           char(77) collate utf8_bin DEFAULT '' NOT NULL,
  created           timestamp,
  modified          timestamp,
  sql_mode          set(
@@ -461,10 +461,12 @@ CREATE TABLE IF NOT EXISTS proc (
                        'TRADITIONAL',
                        'NO_AUTO_CREATE_USER',
                        'HIGH_NOT_PRECEDENCE'
                    ) DEFAULT 0 NOT NULL,
  comment           char(64) binary DEFAULT '' NOT NULL,
                    ) DEFAULT '' NOT NULL,
  comment           char(64) collate utf8_bin DEFAULT '' NOT NULL,
  PRIMARY KEY (db,name,type)
) comment='Stored Procedures';
) engine=MyISAM
  character set utf8
  comment='Stored Procedures';

# Correct the name fields to not binary, and expand sql_data_access
ALTER TABLE proc MODIFY name char(64) DEFAULT '' NOT NULL,
@@ -506,4 +508,15 @@ ALTER TABLE proc MODIFY name char(64) DEFAULT '' NOT NULL,
                            'TRADITIONAL',
                            'NO_AUTO_CREATE_USER',
                            'HIGH_NOT_PRECEDENCE'
                            ) DEFAULT 0 NOT NULL;
                            ) DEFAULT '' NOT NULL
                 DEFAULT CHARACTER SET utf8;

# Correct the character set and collation
ALTER TABLE proc CONVERT TO CHARACTER SET utf8;
# Reset some fields after the conversion
ALTER TABLE proc  MODIFY db
                         char(64) collate utf8_bin DEFAULT '' NOT NULL,
                  MODIFY definer
                         char(77) collate utf8_bin DEFAULT '' NOT NULL,
                  MODIFY comment
                         char(64) collate utf8_bin DEFAULT '' NOT NULL;
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ db_find_routine_aux(THD *thd, int type, sp_name *name,
		    enum thr_lock_type ltype, TABLE **tablep, bool *opened)
{
  TABLE *table;
  byte key[NAME_LEN*2+4+1];	// db, name, optional key length type
  byte key[MAX_KEY_LENGTH];	// db, name, optional key length type
  DBUG_ENTER("db_find_routine_aux");
  DBUG_PRINT("enter", ("type: %d name: %*s",
		       type, name->m_name.length, name->m_name.str));