From e976b27ea65c365953199ac6be9b80479d149525 Mon Sep 17 00:00:00 2001 From: "Tatiana A. Nurnberg" Date: Wed, 11 Mar 2009 19:09:56 +0100 Subject: [PATCH 1/9] Bug#36751: Segmentation fault in ctype-bin.c:308; Linux 86_64, with-max-indexes=128 mysqld is optimized for the default case (up to 64-indices); for a greater number of indices it goes through a different code path. As that code-path is a compile-time option and can not easily be covered in standard tests, bitrot occurred. key-fields need an explicit initialization in the non- optimized case; this setup was presumably not added when a new key- vector was added. Changeset adds the necessary initialisations. No test case added due to dependence on compile-time option. sql/sql_select.cc: Init merge_keys as well. If we don't, things blow up badly outside of the optimized-for-64-keys case! sql/table.cc: Init merge_keys as well. If we don't, things blow up badly outside of the optimized-for-64-keys case! --- sql/sql_select.cc | 1 + sql/table.cc | 1 + 2 files changed, 2 insertions(+) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index bea748562eb..825d3c870d8 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -9788,6 +9788,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, table->in_use= thd; table->quick_keys.init(); table->covering_keys.init(); + table->merge_keys.init(); table->keys_in_use_for_query.init(); table->s= share; diff --git a/sql/table.cc b/sql/table.cc index 17454ffb012..f67929ad96b 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1652,6 +1652,7 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, goto err; outparam->quick_keys.init(); outparam->covering_keys.init(); + outparam->merge_keys.init(); outparam->keys_in_use_for_query.init(); /* Allocate handler */ From 99524127985de26ee61ccc7fd93165f5c14b450b Mon Sep 17 00:00:00 2001 From: Leonard Zhou Date: Thu, 12 Mar 2009 17:48:41 +0800 Subject: [PATCH 2/9] BUG#39858 rpl.rpl_rotate (rpl.rpl_rotate_logs) failed on pushbuild: result mismatch The method to purge binary log files produces different results in some platforms. The reason is that the purge time is calculated based on table modified time and that can't guarantee to purge master-bin.000002 in all platforms.(eg. windows) Use a new way that sets the time to purge binlog file 1 second after the last modified time of master-bin.000002. That can be sure that the file is always deleted in any platform. mysql-test/suite/rpl/r/rpl_rotate_logs.result: Test result mysql-test/suite/rpl/t/rpl_rotate_logs.test: Test file --- mysql-test/suite/rpl/r/rpl_rotate_logs.result | 4 +--- mysql-test/suite/rpl/t/rpl_rotate_logs.test | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_rotate_logs.result b/mysql-test/suite/rpl/r/rpl_rotate_logs.result index 6314a9a61fb..013ba87ec0b 100644 --- a/mysql-test/suite/rpl/r/rpl_rotate_logs.result +++ b/mysql-test/suite/rpl/r/rpl_rotate_logs.result @@ -87,9 +87,7 @@ show binary logs; Log_name File_size master-bin.000002 # master-bin.000003 # -select @time_for_purge:=DATE_ADD(UPDATE_TIME, INTERVAL 1 SECOND) -from information_schema.tables -where TABLE_SCHEMA="test" and TABLE_NAME="t2"; +SELECT @time_for_purge:=DATE_ADD('tmpval', INTERVAL 1 SECOND); purge master logs before (@time_for_purge); show binary logs; Log_name File_size diff --git a/mysql-test/suite/rpl/t/rpl_rotate_logs.test b/mysql-test/suite/rpl/t/rpl_rotate_logs.test index 2bad7b27272..e06099fd707 100644 --- a/mysql-test/suite/rpl/t/rpl_rotate_logs.test +++ b/mysql-test/suite/rpl/t/rpl_rotate_logs.test @@ -112,14 +112,24 @@ source include/show_master_logs.inc; purge binary logs to 'master-bin.000002'; source include/show_binary_logs.inc; -# Calculate time to use in "purge master logs before" by taking -# last modification time of t2 and adding 1 second -# This is donw in order to handle the case where file system -# time differs from mysqld's time +# Set the purge time 1 second after the last modify time of master-bin.000002. +perl; +open F, ">>".$ENV{'MYSQLTEST_VARDIR'}.'/tmp/rpl_rotate_logs.tmp' or die "Tmp file rpl_rotate_logs.tmp not found"; +my $binlogpath = $ENV{'MYSQLTEST_VARDIR'}.'/mysqld.1/data/master-bin.000002'; +my @array = stat($binlogpath); +my $filemodifytime = $array[9]; +my @t = localtime $filemodifytime; +my $modifytime = sprintf "%04u-%02u-%02u %02u:%02u:%02u",$t[5]+1900,$t[4]+1,$t[3],$t[2],$t[1],$t[0]; +printf F ("let \$tmpval = %s;",$modifytime); +close F; +EOF + +--source $MYSQLTEST_VARDIR/tmp/rpl_rotate_logs.tmp +remove_file $MYSQLTEST_VARDIR/tmp/rpl_rotate_logs.tmp; + --disable_result_log -select @time_for_purge:=DATE_ADD(UPDATE_TIME, INTERVAL 1 SECOND) - from information_schema.tables - where TABLE_SCHEMA="test" and TABLE_NAME="t2"; +--replace_result $tmpval tmpval +--eval SELECT @time_for_purge:=DATE_ADD('$tmpval', INTERVAL 1 SECOND) --enable_result_log purge master logs before (@time_for_purge); From f35b4218eaa2bf831ab682b3674851a1cc6ee65a Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 13 Mar 2009 15:51:25 +0200 Subject: [PATCH 3/9] Bug #22047 : Time in SHOW PROCESSLIST for SQL thread in replication seems to become negative THD::start_time has a dual meaning : it's either the time since the process entered a given state or is the transaction time returned by e.g. NOW(). This causes problems, as sometimes THD::start_time may be set to a value that is correct and needed when used as a base for NOW(), but these times may be arbitrary (SET @@timestamp) or non-local (coming from the master through the replication feed). If one such non-local time is set there's no way to return a correct value for e.g. SHOW PROCESSLIST or SELECT ... FROM INFORMATION_SCHEMA.PROCESSLIST. Fixed by making the Time column in SHOW PROCESSLIST SIGNED LONG instead of UNSIGNED LONG and doing the correct conversions. Note that no reliable test suite can be constructed, since it would require knowing the local time and can't be achieved by the means of the current test suite. sql/sql_show.cc: Bug #22047: make the Time in SHOW PROCESSLIST LONG from LONG UNSIGNED --- sql/sql_show.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index a3ccf770a3c..fee3d076436 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1338,7 +1338,8 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) field_list.push_back(field=new Item_empty_string("db",NAME_LEN)); field->maybe_null=1; field_list.push_back(new Item_empty_string("Command",16)); - field_list.push_back(new Item_return_int("Time",7, FIELD_TYPE_LONG)); + field_list.push_back(field= new Item_return_int("Time",7, FIELD_TYPE_LONG)); + field->unsigned_flag= 0; field_list.push_back(field=new Item_empty_string("State",30)); field->maybe_null=1; field_list.push_back(field=new Item_empty_string("Info",max_query_length)); @@ -1439,7 +1440,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) else protocol->store(command_name[thd_info->command], system_charset_info); if (thd_info->start_time) - protocol->store((uint32) (now - thd_info->start_time)); + protocol->store_long ((longlong) (now - thd_info->start_time)); else protocol->store_null(); protocol->store(thd_info->state_info, system_charset_info); From 99eeb9fbbc812ac96d53a215f94aa329e767c88c Mon Sep 17 00:00:00 2001 From: Jonathan Perkin Date: Fri, 13 Mar 2009 21:01:19 +0100 Subject: [PATCH 4/9] Raise version number after cloning 5.1.33 --- configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.in b/configure.in index 069da9ef36e..d86218bd782 100644 --- a/configure.in +++ b/configure.in @@ -10,7 +10,7 @@ AC_CANONICAL_SYSTEM # # When changing major version number please also check switch statement # in mysqlbinlog::check_master_version(). -AM_INIT_AUTOMAKE(mysql, 5.1.33) +AM_INIT_AUTOMAKE(mysql, 5.1.34) AM_CONFIG_HEADER([include/config.h:config.h.in]) PROTOCOL_VERSION=10 From fb4e68b6870401f1c87e5efb2d4b2a70911b363f Mon Sep 17 00:00:00 2001 From: "Tatiana A. Nurnberg" Date: Tue, 17 Mar 2009 18:24:35 +0100 Subject: [PATCH 5/9] 36446: fix Windows warning --- mysys/my_getopt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 54410fc3d1e..4b74cdbf266 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -918,7 +918,7 @@ ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp, if (num < (ulonglong) optp->min_value) { num= (ulonglong) optp->min_value; - if (old < optp->min_value) + if (old < (ulonglong) optp->min_value) adjusted= TRUE; } From 9e655bfffcda0a016943c96c4d911049d38f4c40 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 17 Mar 2009 23:28:24 +0100 Subject: [PATCH 6/9] Bug #43715 Link errors when trying to link mysql_embedded.exe The reason for the error is incorrectly specified link dependencies for mysql_embedded, mysqltest_embedded and mysql_client_test_embedded in CMakeLists.txt (ADD_DEPENDENCIES should be TARGET_LINK_LIBRARIES) libmysqld/CMakeLists.txt: changed library type for libmysqld to SHARED instead of MODULE. MODULE in CMake notation is a shared library that is used only in dlopen/dlsym/LoadLibrary scenarios. Hence it was impossible to use TARGET_LINK_LIBRARIES with a MODULE. libmysqld/examples/CMakeLists.txt: Use TARGET_LINK_LIBRARIES (instead of previously incorrectly used ADD_DEPENDENCIES) to specify link dependency from libmysqld --- libmysqld/CMakeLists.txt | 2 +- libmysqld/examples/CMakeLists.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt index 1582f0898d8..1c8f80768d4 100644 --- a/libmysqld/CMakeLists.txt +++ b/libmysqld/CMakeLists.txt @@ -201,6 +201,6 @@ ADD_LIBRARY(mysqlserver STATIC ${LIBMYSQLD_SOURCES}) ADD_DEPENDENCIES(mysqlserver GenServerSource GenError) TARGET_LINK_LIBRARIES(mysqlserver) -ADD_LIBRARY(libmysqld MODULE cmake_dummy.c libmysqld.def) +ADD_LIBRARY(libmysqld SHARED cmake_dummy.c libmysqld.def) ADD_DEPENDENCIES(libmysqld mysqlserver) TARGET_LINK_LIBRARIES(libmysqld mysqlserver wsock32) diff --git a/libmysqld/examples/CMakeLists.txt b/libmysqld/examples/CMakeLists.txt index fa9711b54da..5194836a728 100644 --- a/libmysqld/examples/CMakeLists.txt +++ b/libmysqld/examples/CMakeLists.txt @@ -30,12 +30,12 @@ ADD_EXECUTABLE(mysql_embedded ../../client/completion_hash.cc ../../client/mysql.cc ../../client/readline.cc ../../client/sql_string.cc) TARGET_LINK_LIBRARIES(mysql_embedded debug dbug strings mysys vio yassl taocrypt regex ws2_32) -ADD_DEPENDENCIES(mysql_embedded libmysqld) +TARGET_LINK_LIBRARIES(mysql_embedded libmysqld) ADD_EXECUTABLE(mysqltest_embedded ../../client/mysqltest.cc) TARGET_LINK_LIBRARIES(mysqltest_embedded debug dbug strings mysys vio yassl taocrypt regex ws2_32) -ADD_DEPENDENCIES(mysqltest_embedded libmysqld) +TARGET_LINK_LIBRARIES(mysqltest_embedded libmysqld) ADD_EXECUTABLE(mysql_client_test_embedded ../../tests/mysql_client_test.c) TARGET_LINK_LIBRARIES(mysql_client_test_embedded debug dbug strings mysys vio yassl taocrypt regex ws2_32) -ADD_DEPENDENCIES(mysql_client_test_embedded libmysqld) +TARGET_LINK_LIBRARIES(mysql_client_test_embedded libmysqld) From 497db6ac0f1efb1a962158d9ee108b0236b88e5c Mon Sep 17 00:00:00 2001 From: Satya B Date: Wed, 18 Mar 2009 11:16:21 +0530 Subject: [PATCH 7/9] Fix for BUG#32880 - Repairing Archive table fails with internal error 144 Any statement reading corrupt archive data file (CHECK/REPAIR/SELECT/UPDATE/DELETE) may cause assertion failure in debug builds. This assertion has been removed and an error is returned instead. Also fixed that CHECK/REPAIR returns vague error message when it mets corruption in archive data file. This is fixed by returning proper error code. mysql-test/r/archive.result: A test case for BUG#32880 mysql-test/std_data/bug32880.ARN: corrupted archive table to test check and repair table operation mysql-test/std_data/bug32880.ARZ: corrupted archive table to test check and repair table operation mysql-test/std_data/bug32880.frm: corrupted archive table to test check and repair table operation mysql-test/t/archive.test: A test case for BUG#32880 storage/archive/ha_archive.cc: Fixed unpack_row() to return the error instead of throwing assertion and also fixed repair() to throw better error when repair table operation fails on corrupted archive table --- mysql-test/r/archive.result | 19 +++++++++++++++++++ mysql-test/std_data/bug32880.ARN | Bin 0 -> 131 bytes mysql-test/std_data/bug32880.ARZ | Bin 0 -> 8744 bytes mysql-test/std_data/bug32880.frm | Bin 0 -> 8578 bytes mysql-test/t/archive.test | 15 +++++++++++++++ storage/archive/ha_archive.cc | 6 ++---- 6 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 mysql-test/std_data/bug32880.ARN create mode 100644 mysql-test/std_data/bug32880.ARZ create mode 100644 mysql-test/std_data/bug32880.frm diff --git a/mysql-test/r/archive.result b/mysql-test/r/archive.result index 8c26ea1ff82..02acccb234e 100644 --- a/mysql-test/r/archive.result +++ b/mysql-test/r/archive.result @@ -12695,3 +12695,22 @@ a b 1 NULL 2 NULL DROP TABLE t1; +# +# BUG#32880 - Repairing Archive table fails with internal error 144 +# + +# Test with an existing table which is corrupted +# Copy t1 from std_data +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` blob +) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check error Corrupt +REPAIR TABLE t1; +Table Op Msg_type Msg_text +test.t1 repair error Corrupt +DROP TABLE t1; diff --git a/mysql-test/std_data/bug32880.ARN b/mysql-test/std_data/bug32880.ARN new file mode 100644 index 0000000000000000000000000000000000000000..643b0dfbad59af05495571978acc8b5eeaf8b509 GIT binary patch literal 131 zcmeyz%qYO%$AAi8dqei4wVSWE@5vi;Yx=ZHHrNyljV=3 gvkA%YRCc;{PVKA|P+c6Av6_|P_LJg8GZ+~d03i_-e*gdg literal 0 HcmV?d00001 diff --git a/mysql-test/std_data/bug32880.ARZ b/mysql-test/std_data/bug32880.ARZ new file mode 100644 index 0000000000000000000000000000000000000000..4e151822647f1b7e0f3f2b9952ef543f9a7954ce GIT binary patch literal 8744 zcmeI&ze>YE90%}kE^WOwLQ_+U|G-v?pi7-QR7DDkP{ct*5RxuFL%>0bOI#ep7w|I1m=0(}aH((^7}($&Gi!uKHg{qC2`-SL@!GuQDk05EFlmmMEA5AD2YV{h9gHUv8Q z`pMQ~=9GO`*BoHqe5%gZ3yCt2?j*CS`S)`S)UraS12nSrP z3Q&Lo|5iXi<#(HBwzPz!i{q2i%YMFu2?Z!X0SZun0u-PC1t>rP3Q&Lo3nnmf(tdyi zyY=5)*MUG6rY)k1Qoiju8oF*q7p@TX-R3U`3J{U*nGi!1gy)$}HtzK{uI`{H3MtJQ zwTC(|Jpfdsh6=j-!j4H4hF@dZzFK<>&h~=%@NQ@It^K_9ep_1ET#l1|@{+`fS*+Bg Wb>pSU>r>;WvOc)BNhQ>$RK5X*A2h-M literal 0 HcmV?d00001 diff --git a/mysql-test/std_data/bug32880.frm b/mysql-test/std_data/bug32880.frm new file mode 100644 index 0000000000000000000000000000000000000000..66a4c7d7538ef06353e4b38b8699203736844857 GIT binary patch literal 8578 zcmeI&u?oU45C-5s*H%+Hw8i4$($%TXT|`9CO&r|YClT?@dj)_ z@U6LrNs9<546x7zIYNj<3M77Shhm}0?Fy7bp=p46*l?u)1t>rP3Q&Lo6rcbFC_n)U zP~d9?1TMVooxMt9tPbn#?zjm@m{5QM6rcbFC_n)UP=Epypa2CZ@M8jJqo4kN90r0G z6BWoY3J!ZrweF)uBvQ@m4+Alz)0qkB5lfc&CbN^aiFAS@5o`S&<)s4dOTcxmcX$FK Cm=+HJ literal 0 HcmV?d00001 diff --git a/mysql-test/t/archive.test b/mysql-test/t/archive.test index 7139d95ab49..0d521f95b38 100644 --- a/mysql-test/t/archive.test +++ b/mysql-test/t/archive.test @@ -1599,3 +1599,18 @@ INSERT INTO t1 VALUES (NULL, NULL),(NULL, NULL); FLUSH TABLE t1; SELECT * FROM t1 ORDER BY a; DROP TABLE t1; + +--echo # +--echo # BUG#32880 - Repairing Archive table fails with internal error 144 +--echo # +--echo +--echo # Test with an existing table which is corrupted +--echo # Copy t1 from std_data +let $MYSQLD_DATADIR= `select @@datadir`; +copy_file std_data/bug32880.frm $MYSQLD_DATADIR/test/t1.frm; +copy_file std_data/bug32880.ARZ $MYSQLD_DATADIR/test/t1.ARZ; +copy_file std_data/bug32880.ARN $MYSQLD_DATADIR/test/t1.ARN; +SHOW CREATE TABLE t1; +CHECK TABLE t1; +REPAIR TABLE t1; +DROP TABLE t1; diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index 7edfca53751..d20ab3bf723 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -1076,11 +1076,9 @@ int ha_archive::unpack_row(azio_stream *file_to_read, uchar *record) read= azread(file_to_read, record_buffer->buffer, row_len, &error); - DBUG_ASSERT(row_len == read); - if (read != row_len || error) { - DBUG_RETURN(-1); + DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); } /* Copy null bits */ @@ -1257,7 +1255,7 @@ int ha_archive::repair(THD* thd, HA_CHECK_OPT* check_opt) int rc= optimize(thd, check_opt); if (rc) - DBUG_RETURN(HA_ERR_CRASHED_ON_REPAIR); + DBUG_RETURN(HA_ADMIN_CORRUPT); share->crashed= FALSE; DBUG_RETURN(0); From 0ba1cc2523f1c7603627d0d683355d042ea85b65 Mon Sep 17 00:00:00 2001 From: Guangbao Ni Date: Wed, 18 Mar 2009 13:48:23 +0000 Subject: [PATCH 8/9] Bug #42217 mysql.procs_priv does not get replicated mysql.procs_priv table itself does not get replicated. Inserting routine privilege record into mysql.procs_priv table is triggered by creating function/procedure statements according to current user's privileges. Because the current user of SQL thread has GLOBAL_ACL, which doesn't need any check mysql.procs_priv privilege when create/alter/execute routines. Corresponding GLOBAL_ACL privilege user doesn't insert routine privilege record into mysql.procs_priv when creating a routine. Fixed by switching the current user of SQL thread to definer user if the definer user exists on slave. That populates procs_priv, otherwise to keep the SQL thread user and procs_priv remains unchanged. mysql-test/suite/rpl/r/rpl_do_grant.result: Test case result for routine privilege when definer user exist or not on slave mysql-test/suite/rpl/t/rpl_do_grant.test: Test case result for routine privilege when definer user exist or not on slave sql/sql_parse.cc: Switch current user of SQL thread to definer user if the definer user existes on slave when checking whether the routine privilege is needed to insert mysql.procs_priv table or not. --- mysql-test/suite/rpl/r/rpl_do_grant.result | 78 +++++++++++++++++ mysql-test/suite/rpl/t/rpl_do_grant.test | 97 ++++++++++++++++++++++ sql/sql_parse.cc | 36 +++++++- 3 files changed, 210 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/rpl/r/rpl_do_grant.result b/mysql-test/suite/rpl/r/rpl_do_grant.result index f7f1ce66656..69bcfad4347 100644 --- a/mysql-test/suite/rpl/r/rpl_do_grant.result +++ b/mysql-test/suite/rpl/r/rpl_do_grant.result @@ -89,3 +89,81 @@ show grants for rpl_do_grant2@localhost; ERROR 42000: There is no such grant defined for user 'rpl_do_grant2' on host 'localhost' show grants for rpl_do_grant2@localhost; ERROR 42000: There is no such grant defined for user 'rpl_do_grant2' on host 'localhost' +DROP DATABASE IF EXISTS bug42217_db; +CREATE DATABASE bug42217_db; +GRANT CREATE ROUTINE ON bug42217_db.* TO 'create_rout_db'@'localhost' + IDENTIFIED BY 'create_rout_db' WITH GRANT OPTION; +USE bug42217_db; +CREATE FUNCTION upgrade_del_func() RETURNS CHAR(30) +BEGIN +RETURN "INSIDE upgrade_del_func()"; +END// +USE bug42217_db; +SELECT * FROM mysql.procs_priv; +Host Db User Routine_name Routine_type Grantor Proc_priv Timestamp +localhost bug42217_db create_rout_db upgrade_del_func FUNCTION create_rout_db@localhost Execute,Alter Routine # +SELECT upgrade_del_func(); +upgrade_del_func() +INSIDE upgrade_del_func() +SELECT * FROM mysql.procs_priv; +Host Db User Routine_name Routine_type Grantor Proc_priv Timestamp +localhost bug42217_db create_rout_db upgrade_del_func FUNCTION create_rout_db@localhost Execute,Alter Routine # +SHOW GRANTS FOR 'create_rout_db'@'localhost'; +Grants for create_rout_db@localhost +GRANT USAGE ON *.* TO 'create_rout_db'@'localhost' IDENTIFIED BY PASSWORD '*08792480350CBA057BDE781B9DF183B263934601' +GRANT CREATE ROUTINE ON `bug42217_db`.* TO 'create_rout_db'@'localhost' WITH GRANT OPTION +GRANT EXECUTE, ALTER ROUTINE ON FUNCTION `bug42217_db`.`upgrade_del_func` TO 'create_rout_db'@'localhost' +USE bug42217_db; +SHOW CREATE FUNCTION upgrade_del_func; +Function sql_mode Create Function character_set_client collation_connection Database Collation +upgrade_del_func CREATE DEFINER=`create_rout_db`@`localhost` FUNCTION `upgrade_del_func`() RETURNS char(30) CHARSET latin1 +BEGIN +RETURN "INSIDE upgrade_del_func()"; +END latin1 latin1_swedish_ci latin1_swedish_ci +SELECT upgrade_del_func(); +upgrade_del_func() +INSIDE upgrade_del_func() +"Check whether the definer user will be able to execute the replicated routine on slave" +USE bug42217_db; +SHOW CREATE FUNCTION upgrade_del_func; +Function sql_mode Create Function character_set_client collation_connection Database Collation +upgrade_del_func CREATE DEFINER=`create_rout_db`@`localhost` FUNCTION `upgrade_del_func`() RETURNS char(30) CHARSET latin1 +BEGIN +RETURN "INSIDE upgrade_del_func()"; +END latin1 latin1_swedish_ci latin1_swedish_ci +SELECT upgrade_del_func(); +upgrade_del_func() +INSIDE upgrade_del_func() +DELETE FROM mysql.procs_priv; +FLUSH PRIVILEGES; +USE bug42217_db; +"Can't execute the replicated routine on slave like before after procs privilege is deleted " +SELECT upgrade_del_func(); +ERROR 42000: execute command denied to user 'create_rout_db'@'localhost' for routine 'bug42217_db.upgrade_del_func' +"Test the user who creates a function on master doesn't exist on slave." +"Hence SQL thread ACL_GLOBAL privilege jumps in and no mysql.procs_priv is inserted" +DROP USER 'create_rout_db'@'localhost'; +CREATE FUNCTION upgrade_alter_func() RETURNS CHAR(30) +BEGIN +RETURN "INSIDE upgrade_alter_func()"; +END// +SELECT upgrade_alter_func(); +upgrade_alter_func() +INSIDE upgrade_alter_func() +SHOW CREATE FUNCTION upgrade_alter_func; +Function sql_mode Create Function character_set_client collation_connection Database Collation +upgrade_alter_func CREATE DEFINER=`create_rout_db`@`localhost` FUNCTION `upgrade_alter_func`() RETURNS char(30) CHARSET latin1 +BEGIN +RETURN "INSIDE upgrade_alter_func()"; +END latin1 latin1_swedish_ci latin1_swedish_ci +"Should no privilege record for upgrade_alter_func in mysql.procs_priv" +SELECT * FROM mysql.procs_priv; +Host Db User Routine_name Routine_type Grantor Proc_priv Timestamp +SELECT upgrade_alter_func(); +ERROR HY000: The user specified as a definer ('create_rout_db'@'localhost') does not exist +USE bug42217_db; +DROP FUNCTION upgrade_del_func; +DROP FUNCTION upgrade_alter_func; +DROP DATABASE bug42217_db; +DROP USER 'create_rout_db'@'localhost'; +"End of test" diff --git a/mysql-test/suite/rpl/t/rpl_do_grant.test b/mysql-test/suite/rpl/t/rpl_do_grant.test index 5615900c2dd..806de780086 100644 --- a/mysql-test/suite/rpl/t/rpl_do_grant.test +++ b/mysql-test/suite/rpl/t/rpl_do_grant.test @@ -112,3 +112,100 @@ show grants for rpl_do_grant2@localhost; sync_slave_with_master; --error 1141 show grants for rpl_do_grant2@localhost; + +##################################################### +# Purpose +# Test whether mysql.procs_priv get replicated +# Related bugs: +# BUG42217 mysql.procs_priv does not get replicated +##################################################### +connection master; + +--disable_warnings +DROP DATABASE IF EXISTS bug42217_db; +--enable_warnings +CREATE DATABASE bug42217_db; + +GRANT CREATE ROUTINE ON bug42217_db.* TO 'create_rout_db'@'localhost' + IDENTIFIED BY 'create_rout_db' WITH GRANT OPTION; + +connect (create_rout_db_master, localhost, create_rout_db, create_rout_db, bug42217_db,$MASTER_MYPORT,); +connect (create_rout_db_slave, localhost, create_rout_db, create_rout_db, bug42217_db, $SLAVE_MYPORT,); + +connection create_rout_db_master; + + +USE bug42217_db; + +DELIMITER //; +CREATE FUNCTION upgrade_del_func() RETURNS CHAR(30) +BEGIN + RETURN "INSIDE upgrade_del_func()"; +END// + +DELIMITER ;// + +connection master; + +USE bug42217_db; +--replace_column 8 # +SELECT * FROM mysql.procs_priv; +SELECT upgrade_del_func(); + +sync_slave_with_master; +--replace_column 8 # +SELECT * FROM mysql.procs_priv; +SHOW GRANTS FOR 'create_rout_db'@'localhost'; + +USE bug42217_db; +SHOW CREATE FUNCTION upgrade_del_func; +SELECT upgrade_del_func(); + +--echo "Check whether the definer user will be able to execute the replicated routine on slave" +connection create_rout_db_slave; +USE bug42217_db; +SHOW CREATE FUNCTION upgrade_del_func; +SELECT upgrade_del_func(); + +connection slave; +DELETE FROM mysql.procs_priv; +FLUSH PRIVILEGES; +USE bug42217_db; +--echo "Can't execute the replicated routine on slave like before after procs privilege is deleted " +--error 1370 +SELECT upgrade_del_func(); + +--echo "Test the user who creates a function on master doesn't exist on slave." +--echo "Hence SQL thread ACL_GLOBAL privilege jumps in and no mysql.procs_priv is inserted" +DROP USER 'create_rout_db'@'localhost'; + +connection create_rout_db_master; +DELIMITER //; +CREATE FUNCTION upgrade_alter_func() RETURNS CHAR(30) +BEGIN + RETURN "INSIDE upgrade_alter_func()"; +END// +DELIMITER ;// + +connection master; +SELECT upgrade_alter_func(); + +sync_slave_with_master; +SHOW CREATE FUNCTION upgrade_alter_func; +--echo "Should no privilege record for upgrade_alter_func in mysql.procs_priv" +--replace_column 8 # +SELECT * FROM mysql.procs_priv; +--error 1449 +SELECT upgrade_alter_func(); + +###### CLEAN UP SECTION ############## +disconnect create_rout_db_master; +disconnect create_rout_db_slave; +connection master; +USE bug42217_db; +DROP FUNCTION upgrade_del_func; +DROP FUNCTION upgrade_alter_func; +DROP DATABASE bug42217_db; +DROP USER 'create_rout_db'@'localhost'; + +--echo "End of test" diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f7e895d150f..94725b1b53f 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4129,9 +4129,32 @@ end_with_restore_list: res= (sp_result= lex->sphead->create(thd)); switch (sp_result) { - case SP_OK: + case SP_OK: { #ifndef NO_EMBEDDED_ACCESS_CHECKS /* only add privileges if really neccessary */ + + Security_context security_context; + bool restore_backup_context= false; + Security_context *backup= NULL; + LEX_USER *definer= thd->lex->definer; + /* + Check if the definer exists on slave, + then use definer privilege to insert routine privileges to mysql.procs_priv. + + For current user of SQL thread has GLOBAL_ACL privilege, + which doesn't any check routine privileges, + so no routine privilege record will insert into mysql.procs_priv. + */ + if (thd->slave_thread && is_acl_user(definer->host.str, definer->user.str)) + { + security_context.change_security_context(thd, + &thd->lex->definer->user, + &thd->lex->definer->host, + &thd->lex->sphead->m_db, + &backup); + restore_backup_context= true; + } + if (sp_automatic_privileges && !opt_noacl && check_routine_access(thd, DEFAULT_CREATE_PROC_ACLS, lex->sphead->m_db.str, name, @@ -4143,8 +4166,19 @@ end_with_restore_list: ER_PROC_AUTO_GRANT_FAIL, ER(ER_PROC_AUTO_GRANT_FAIL)); } + + /* + Restore current user with GLOBAL_ACL privilege of SQL thread + */ + if (restore_backup_context) + { + DBUG_ASSERT(thd->slave_thread == 1); + thd->security_ctx->restore_security_context(thd, backup); + } + #endif break; + } case SP_WRITE_ROW_FAILED: my_error(ER_SP_ALREADY_EXISTS, MYF(0), SP_TYPE_STRING(lex), name); break; From 6290bc7e61ed97fb7af629c5e4c6f6d9e3ccc9b0 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Wed, 18 Mar 2009 14:52:31 +0200 Subject: [PATCH 9/9] addendum to the 22047 fix : updated funcs_1 test suite --- mysql-test/suite/funcs_1/r/is_columns_is.result | 5 +++-- mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result | 4 ++-- mysql-test/suite/funcs_1/r/processlist_val_no_prot.result | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mysql-test/suite/funcs_1/r/is_columns_is.result b/mysql-test/suite/funcs_1/r/is_columns_is.result index 94aa75c6db2..ccb94c63d46 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_is.result +++ b/mysql-test/suite/funcs_1/r/is_columns_is.result @@ -166,7 +166,7 @@ NULL information_schema PROCESSLIST HOST 3 NO varchar 64 192 NULL NULL utf8 utf NULL information_schema PROCESSLIST ID 1 0 NO bigint NULL NULL 19 0 NULL NULL bigint(4) select NULL information_schema PROCESSLIST INFO 8 NULL YES longtext 4294967295 4294967295 NULL NULL utf8 utf8_general_ci longtext select NULL information_schema PROCESSLIST STATE 7 NULL YES varchar 64 192 NULL NULL utf8 utf8_general_ci varchar(64) select -NULL information_schema PROCESSLIST TIME 6 0 NO bigint NULL NULL 19 0 NULL NULL bigint(7) select +NULL information_schema PROCESSLIST TIME 6 0 NO int NULL NULL 10 0 NULL NULL int(7) select NULL information_schema PROCESSLIST USER 2 NO varchar 16 48 NULL NULL utf8 utf8_general_ci varchar(16) select NULL information_schema REFERENTIAL_CONSTRAINTS CONSTRAINT_CATALOG 1 NULL YES varchar 512 1536 NULL NULL utf8 utf8_general_ci varchar(512) select NULL information_schema REFERENTIAL_CONSTRAINTS CONSTRAINT_NAME 3 NO varchar 64 192 NULL NULL utf8 utf8_general_ci varchar(64) select @@ -340,6 +340,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML; COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME NULL bigint NULL NULL NULL datetime NULL NULL +NULL int NULL NULL --> CHAR(0) is allowed (see manual), and here both CHARACHTER_* values --> are 0, which is intended behavior, and the result of 0 / 0 IS NULL SELECT CHARACTER_OCTET_LENGTH / CHARACTER_MAXIMUM_LENGTH AS COL_CML, @@ -519,7 +520,7 @@ NULL information_schema PROCESSLIST ID bigint NULL NULL NULL NULL bigint(4) 3.0000 information_schema PROCESSLIST HOST varchar 64 192 utf8 utf8_general_ci varchar(64) 3.0000 information_schema PROCESSLIST DB varchar 64 192 utf8 utf8_general_ci varchar(64) 3.0000 information_schema PROCESSLIST COMMAND varchar 16 48 utf8 utf8_general_ci varchar(16) -NULL information_schema PROCESSLIST TIME bigint NULL NULL NULL NULL bigint(7) +NULL information_schema PROCESSLIST TIME int NULL NULL NULL NULL int(7) 3.0000 information_schema PROCESSLIST STATE varchar 64 192 utf8 utf8_general_ci varchar(64) 1.0000 information_schema PROCESSLIST INFO longtext 4294967295 4294967295 utf8 utf8_general_ci longtext 3.0000 information_schema REFERENTIAL_CONSTRAINTS CONSTRAINT_CATALOG varchar 512 1536 utf8 utf8_general_ci varchar(512) diff --git a/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result b/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result index d862b7424e0..3d341292be1 100644 --- a/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result +++ b/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result @@ -27,7 +27,7 @@ PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` ( `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', - `TIME` bigint(7) NOT NULL DEFAULT '0', + `TIME` int(7) NOT NULL DEFAULT '0', `STATE` varchar(64) DEFAULT NULL, `INFO` longtext ) ENGINE=MyISAM DEFAULT CHARSET=utf8 @@ -97,7 +97,7 @@ PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` ( `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', - `TIME` bigint(7) NOT NULL DEFAULT '0', + `TIME` int(7) NOT NULL DEFAULT '0', `STATE` varchar(64) DEFAULT NULL, `INFO` longtext ) ENGINE=MyISAM DEFAULT CHARSET=utf8 diff --git a/mysql-test/suite/funcs_1/r/processlist_val_no_prot.result b/mysql-test/suite/funcs_1/r/processlist_val_no_prot.result index 482e143fd23..b0cae801fd6 100644 --- a/mysql-test/suite/funcs_1/r/processlist_val_no_prot.result +++ b/mysql-test/suite/funcs_1/r/processlist_val_no_prot.result @@ -17,7 +17,7 @@ PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` ( `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', - `TIME` bigint(7) NOT NULL DEFAULT '0', + `TIME` int(7) NOT NULL DEFAULT '0', `STATE` varchar(64) DEFAULT NULL, `INFO` longtext ) ENGINE=MyISAM DEFAULT CHARSET=utf8