From 9a87702b033bc9bab337e716a52532c4e4599057 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 28 Nov 2006 16:03:53 +0100 Subject: [PATCH 1/2] Bug#22043 MySQL don't add "USE " before "DROP PROCEDURE EXISTS" - CREATE PROCEDURE stores database name based on query context instead of 'current database' as set by 'USE' according to manual. The bug reporter interpret the filtering statements as bug for DROP PROCEDURE based on this behavior. - Removed the code which changes db context. - Added code to check that a valid db was supplied. mysql-test/r/rpl_sp.result: - Added test case (result) mysql-test/t/rpl_sp.test: - Added test case sql/sp.cc: - Removed code for changing current db context. sql/sql_parse.cc: - Added code to check if a valid db was supplied. --- mysql-test/r/rpl_sp.result | 25 +++++++++++++++++++++++++ mysql-test/t/rpl_sp.test | 23 +++++++++++++++++++++++ sql/sp.cc | 9 --------- sql/sql_parse.cc | 24 ++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/rpl_sp.result b/mysql-test/r/rpl_sp.result index 7b096b27733..d6f9880de17 100644 --- a/mysql-test/r/rpl_sp.result +++ b/mysql-test/r/rpl_sp.result @@ -465,3 +465,28 @@ RETURN 0 DROP PROCEDURE p1; DROP FUNCTION f1; drop table t1; +drop database if exists mysqltest; +drop database if exists mysqltest2; +create database mysqltest; +create database mysqltest2; +use mysqltest2; +create table t ( t integer ); +create procedure mysqltest.test() begin end; +insert into t values ( 1 ); +show binlog events in 'master-bin.000001' from 8186; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 8186 Query 1 8317 use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION f1() RETURNS INT RETURN 0 +master-bin.000001 8317 Query 1 8397 use `test`; DROP PROCEDURE p1 +master-bin.000001 8397 Query 1 8476 use `test`; DROP FUNCTION f1 +master-bin.000001 8476 Query 1 8552 use `test`; drop table t1 +master-bin.000001 8552 Query 1 8653 drop database if exists mysqltest +master-bin.000001 8653 Query 1 8756 drop database if exists mysqltest2 +master-bin.000001 8756 Query 1 8849 create database mysqltest +master-bin.000001 8849 Query 1 8944 create database mysqltest2 +master-bin.000001 8944 Query 1 9041 use `mysqltest2`; create table t ( t integer ) +master-bin.000001 9041 Query 1 9180 use `mysqltest2`; CREATE DEFINER=`root`@`localhost` procedure mysqltest.test() begin end +master-bin.000001 9180 Query 1 9275 use `mysqltest2`; insert into t values ( 1 ) +create procedure `\\`.test() begin end; +ERROR 42000: Incorrect database name '\\' +drop database mysqltest; +drop database mysqltest2; diff --git a/mysql-test/t/rpl_sp.test b/mysql-test/t/rpl_sp.test index 7479794eded..b7a9036908c 100644 --- a/mysql-test/t/rpl_sp.test +++ b/mysql-test/t/rpl_sp.test @@ -519,3 +519,26 @@ DROP FUNCTION f1; connection master; drop table t1; sync_slave_with_master; + +# +# Bug22043: MySQL don't add "USE " before "DROP PROCEDURE IF EXISTS" +# +connection master; +--disable_warnings +drop database if exists mysqltest; +drop database if exists mysqltest2; +--enable_warnings +create database mysqltest; +create database mysqltest2; +use mysqltest2; +create table t ( t integer ); +create procedure mysqltest.test() begin end; +insert into t values ( 1 ); +show binlog events in 'master-bin.000001' from 8186; +--error ER_WRONG_DB_NAME +create procedure `\\`.test() begin end; +# Clean up +drop database mysqltest; +drop database mysqltest2; + + diff --git a/sql/sp.cc b/sql/sp.cc index 283f43f55b2..f7c086061d3 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -494,17 +494,10 @@ db_create_routine(THD *thd, int type, sp_head *sp) char definer[USER_HOST_BUFF_SIZE]; char old_db_buf[NAME_LEN+1]; LEX_STRING old_db= { old_db_buf, sizeof(old_db_buf) }; - bool dbchanged; DBUG_ENTER("db_create_routine"); DBUG_PRINT("enter", ("type: %d name: %.*s",type,sp->m_name.length, sp->m_name.str)); - if ((ret= sp_use_new_db(thd, sp->m_db, &old_db, 0, &dbchanged))) - { - ret= SP_NO_DB_ERROR; - goto done; - } - if (!(table= open_proc_table_for_update(thd))) ret= SP_OPEN_TABLE_FAILED; else @@ -629,8 +622,6 @@ db_create_routine(THD *thd, int type, sp_head *sp) done: close_thread_tables(thd); - if (dbchanged) - (void) mysql_change_db(thd, old_db.str, 1); DBUG_RETURN(ret); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 3a107c2296c..2feaebdde25 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4226,6 +4226,30 @@ end_with_restore_list: DBUG_ASSERT(lex->sphead != 0); DBUG_ASSERT(lex->sphead->m_db.str); /* Must be initialized in the parser */ + /* + Verify that the database name is allowed, optionally + lowercase it. + */ + if (check_db_name(lex->sphead->m_db.str)) + { + my_error(ER_WRONG_DB_NAME, MYF(0), lex->sphead->m_db.str); + delete lex->sphead; + lex->sphead= 0; + goto error; + } + + /* + Check that a database with this name + exists. + */ + if (check_db_dir_existence(lex->sphead->m_db.str)) + { + my_error(ER_BAD_DB_ERROR, MYF(0), lex->sphead->m_db.str); + delete lex->sphead; + lex->sphead= 0; + goto error; + } + if (check_access(thd, CREATE_PROC_ACL, lex->sphead->m_db.str, 0, 0, 0, is_schema_db(lex->sphead->m_db.str))) { From bcf2616909f89127ef280ae167eb754bc82fc90d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 29 Nov 2006 11:45:29 +0100 Subject: [PATCH 2/2] Bug#22043 MySQL don't add "USE " before "DROP PROCEDURE IF EXISTS" - Merge patch. - Test case needed update because event number were off. - Error code has changed because db name validation rules changes between 5.0 and 5.1 mysql-test/r/rpl_sp.result: - Updated result file mysql-test/t/rpl_sp.test: - Changed bin log event number - Changed error code --- mysql-test/r/rpl_sp.result | 24 +++++++++--------------- mysql-test/t/rpl_sp.test | 7 ++++--- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/mysql-test/r/rpl_sp.result b/mysql-test/r/rpl_sp.result index e0d8d6d1db0..f3754f650fb 100644 --- a/mysql-test/r/rpl_sp.result +++ b/mysql-test/r/rpl_sp.result @@ -467,7 +467,7 @@ DROP FUNCTION f1; drop table t1; set global log_bin_trust_function_creators=0; set global log_bin_trust_function_creators=0; - +End of 5.0 tests drop database if exists mysqltest; drop database if exists mysqltest2; create database mysqltest; @@ -476,22 +476,16 @@ use mysqltest2; create table t ( t integer ); create procedure mysqltest.test() begin end; insert into t values ( 1 ); -show binlog events in 'master-bin.000001' from 8186; +show binlog events in 'master-bin.000001' from 8657; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 8186 Query 1 8317 use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION f1() RETURNS INT RETURN 0 -master-bin.000001 8317 Query 1 8397 use `test`; DROP PROCEDURE p1 -master-bin.000001 8397 Query 1 8476 use `test`; DROP FUNCTION f1 -master-bin.000001 8476 Query 1 8552 use `test`; drop table t1 -master-bin.000001 8552 Query 1 8653 drop database if exists mysqltest -master-bin.000001 8653 Query 1 8756 drop database if exists mysqltest2 -master-bin.000001 8756 Query 1 8849 create database mysqltest -master-bin.000001 8849 Query 1 8944 create database mysqltest2 -master-bin.000001 8944 Query 1 9041 use `mysqltest2`; create table t ( t integer ) -master-bin.000001 9041 Query 1 9180 use `mysqltest2`; CREATE DEFINER=`root`@`localhost` procedure mysqltest.test() begin end -master-bin.000001 9180 Query 1 9275 use `mysqltest2`; insert into t values ( 1 ) +master-bin.000001 8657 Query 1 8760 drop database if exists mysqltest2 +master-bin.000001 8760 Query 1 8853 create database mysqltest +master-bin.000001 8853 Query 1 8948 create database mysqltest2 +master-bin.000001 8948 Query 1 9045 use `mysqltest2`; create table t ( t integer ) +master-bin.000001 9045 Query 1 9184 use `mysqltest2`; CREATE DEFINER=`root`@`localhost` procedure mysqltest.test() begin end +master-bin.000001 9184 Query 1 9279 use `mysqltest2`; insert into t values ( 1 ) create procedure `\\`.test() begin end; -ERROR 42000: Incorrect database name '\\' +ERROR 42000: Unknown database '\\' drop database mysqltest; drop database mysqltest2; -End of 5.0 tests End of 5.1 tests diff --git a/mysql-test/t/rpl_sp.test b/mysql-test/t/rpl_sp.test index 0e0de7cf2e7..2f0d04eff35 100644 --- a/mysql-test/t/rpl_sp.test +++ b/mysql-test/t/rpl_sp.test @@ -526,6 +526,8 @@ sync_slave_with_master; set global log_bin_trust_function_creators=0; connection master; set global log_bin_trust_function_creators=0; +--echo End of 5.0 tests + # # Bug22043: MySQL don't add "USE " before "DROP PROCEDURE IF EXISTS" # @@ -540,13 +542,12 @@ use mysqltest2; create table t ( t integer ); create procedure mysqltest.test() begin end; insert into t values ( 1 ); -show binlog events in 'master-bin.000001' from 8186; ---error ER_WRONG_DB_NAME +show binlog events in 'master-bin.000001' from 8657; +--error ER_BAD_DB_ERROR create procedure `\\`.test() begin end; # Clean up drop database mysqltest; drop database mysqltest2; ---echo End of 5.0 tests --echo End of 5.1 tests