From: Date: October 19 2005 12:46pm Subject: bk commit into 5.0 tree (konstantin:1.2019) BUG#13587 List-Archive: http://lists.mysql.com/internals/31251 X-Bug: 13587 Message-Id: <20051019104646.4B3AEDEF@dragonfly.local> Below is the list of changes that have just been committed into a local 5.0 repository of kostja. When kostja does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2019 05/10/19 14:46:32 konstantin@stripped +3 -0 A fix and a test case for Bug#13587 "Server crash when SP is created without database" sql/sql_parse.cc 1.507 05/10/19 14:45:59 konstantin@stripped +29 -7 - move initialization of lex->sphead->m_db before it's used. - cleanup; comment why right now can't be cleaned any more mysql-test/t/sp-error.test 1.91 05/10/19 14:45:59 konstantin@stripped +18 -0 A test case for Bug#13587 "Server crash when SP is created without database" mysql-test/r/sp-error.result 1.87 05/10/19 14:45:59 konstantin@stripped +11 -0 Test results fixed (a test case for Bug#13587) # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: konstantin # Host: dragonfly.local # Root: /opt/local/work/mysql-5.0-13587 --- 1.506/sql/sql_parse.cc 2005-10-13 13:12:07 +04:00 +++ 1.507/sql/sql_parse.cc 2005-10-19 14:45:59 +04:00 @@ -4068,6 +4068,19 @@ DBUG_ASSERT(lex->sphead != 0); + if (!lex->sphead->m_db.str || !lex->sphead->m_db.str[0]) + { + if (! thd->db) + { + my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); + delete lex->sphead; + lex->sphead= 0; + goto error; + } + lex->sphead->m_db.length= strlen(thd->db); + lex->sphead->m_db.str= thd->db; + } + if (check_access(thd, CREATE_PROC_ACL, lex->sphead->m_db.str, 0, 0, 0, is_schema_db(lex->sphead->m_db.str))) { @@ -4077,13 +4090,10 @@ } if (end_active_trans(thd)) - goto error; - - if (!lex->sphead->m_db.str || !lex->sphead->m_db.str[0]) { - lex->sphead->m_db.length= strlen(thd->db); - lex->sphead->m_db.str= strmake_root(thd->mem_root, thd->db, - lex->sphead->m_db.length); + delete lex->sphead; + lex->sphead= 0; + goto error; } name= lex->sphead->name(&namelen); @@ -4110,11 +4120,23 @@ goto error; } + /* + We need to copy name and db in order to use them for + check_routine_access which is called after lex->sphead has + been deleted. + */ name= thd->strdup(name); - db= thd->strmake(lex->sphead->m_db.str, lex->sphead->m_db.length); + lex->sphead->m_db.str= db= thd->strmake(lex->sphead->m_db.str, + lex->sphead->m_db.length); res= (result= lex->sphead->create(thd)); if (result == SP_OK) { + /* + We must cleanup the unit and the lex here because + sp_grant_privileges calls (indirectly) db_find_routine, + which in turn may call yyparse with THD::lex. + TODO: fix db_find_routine to use a temporary lex. + */ lex->unit.cleanup(); delete lex->sphead; lex->sphead= 0; --- 1.86/mysql-test/r/sp-error.result 2005-10-17 19:08:51 +04:00 +++ 1.87/mysql-test/r/sp-error.result 2005-10-19 14:45:59 +04:00 @@ -872,3 +872,14 @@ foo4 drop procedure bug13510_3| drop procedure bug13510_4| +create database mysqltest1; +use mysqltest1; +drop database mysqltest1; +create function f1() returns int return 1; +ERROR 3D000: No database selected +create procedure p1(out param1 int) +begin +select count(*) into param1 from t3; +end| +ERROR 3D000: No database selected +use test; --- 1.90/mysql-test/t/sp-error.test 2005-10-17 19:08:54 +04:00 +++ 1.91/mysql-test/t/sp-error.test 2005-10-19 14:45:59 +04:00 @@ -1266,6 +1266,24 @@ delimiter ;| # +# Bug#13514 "server crash when create a stored procedure before choose a +# database" and +# Bug#13587 "Server crash when SP is created without database +# selected" +# +create database mysqltest1; +use mysqltest1; +drop database mysqltest1; +--error ER_NO_DB_ERROR +create function f1() returns int return 1; +delimiter |; +--error ER_NO_DB_ERROR +create procedure p1(out param1 int) +begin + select count(*) into param1 from t3; +end| +delimiter ;| +use test; # BUG#NNNN: New bug synopsis # #--disable_warnings