Commit 289c1493 authored by Luis Soares's avatar Luis Soares

BUG#49119: Master crashes when executing 'REVOKE ... ON

{PROCEDURE|FUNCTION} FROM ...'

The master would hit an assertion when binary log was
active. This was due to the fact that the thread's diagnostics
area was being cleared before writing to the binlog,
independently of mysql_routine_grant returning an error or
not. When mysql_routine_grant was to return an error, the return
value and the diagnostics area contents would
mismatch. Consequently, neither my_ok would be called nor an
error would be signaled in the diagnostics area, eventually
triggering the assertion in net_end_statement.

We fix this by not clearing the diagnostics area at binlogging
time. 
parent f6ff4a58
......@@ -169,4 +169,77 @@ DROP USER 'create_rout_db'@'localhost';
call mtr.add_suppression("Slave: Operation DROP USER failed for 'create_rout_db'@'localhost' Error_code: 1396");
USE mtr;
call mtr.add_suppression("Slave: Operation DROP USER failed for 'create_rout_db'@'localhost' Error_code: 1396");
######## BUG#49119 #######
### i) test case from the 'how to repeat section'
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
CREATE TABLE t1(c1 INT);
CREATE PROCEDURE p1() SELECT * FROM t1 |
REVOKE EXECUTE ON PROCEDURE p1 FROM 'root'@'localhost';
ERROR 42000: There is no such grant defined for user 'root' on host 'localhost' on routine 'p1'
DROP TABLE t1;
DROP PROCEDURE p1;
### ii) Test case in which REVOKE partially succeeds
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
CREATE TABLE t1(c1 INT);
CREATE PROCEDURE p1() SELECT * FROM t1 |
CREATE USER 'user49119'@'localhost';
GRANT EXECUTE ON PROCEDURE p1 TO 'user49119'@'localhost';
##############################################################
### Showing grants for both users: root and user49119 (master)
SHOW GRANTS FOR 'user49119'@'localhost';
Grants for user49119@localhost
GRANT USAGE ON *.* TO 'user49119'@'localhost'
GRANT EXECUTE ON PROCEDURE `test`.`p1` TO 'user49119'@'localhost'
SHOW GRANTS FOR CURRENT_USER;
Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
##############################################################
##############################################################
### Showing grants for both users: root and user49119 (master)
SHOW GRANTS FOR 'user49119'@'localhost';
Grants for user49119@localhost
GRANT USAGE ON *.* TO 'user49119'@'localhost'
GRANT EXECUTE ON PROCEDURE `test`.`p1` TO 'user49119'@'localhost'
SHOW GRANTS FOR CURRENT_USER;
Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
##############################################################
## This statement will make the revoke fail because root has no
## execute grant. However, it will still revoke the grant for
## user49119.
REVOKE EXECUTE ON PROCEDURE p1 FROM 'user49119'@'localhost', 'root'@'localhost';
ERROR 42000: There is no such grant defined for user 'root' on host 'localhost' on routine 'p1'
##############################################################
### Showing grants for both users: root and user49119 (master)
### after revoke statement failure
SHOW GRANTS FOR 'user49119'@'localhost';
Grants for user49119@localhost
GRANT USAGE ON *.* TO 'user49119'@'localhost'
SHOW GRANTS FOR CURRENT_USER;
Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
##############################################################
#############################################################
### Showing grants for both users: root and user49119 (slave)
### after revoke statement failure (should match
SHOW GRANTS FOR 'user49119'@'localhost';
Grants for user49119@localhost
GRANT USAGE ON *.* TO 'user49119'@'localhost'
SHOW GRANTS FOR CURRENT_USER;
Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
##############################################################
DROP TABLE t1;
DROP PROCEDURE p1;
DROP USER 'user49119'@'localhost';
"End of test"
......@@ -216,4 +216,104 @@ connection slave;
USE mtr;
call mtr.add_suppression("Slave: Operation DROP USER failed for 'create_rout_db'@'localhost' Error_code: 1396");
# BUG#49119: Master crashes when executing 'REVOKE ... ON
# {PROCEDURE|FUNCTION} FROM ...'
#
# The tests are divided into two test cases:
#
# i) a test case that mimics the one in the bug report.
#
# - We show that, despite the fact, that a revoke command fails
# when binlogging is active, the master will not hit an
# assertion.
#
# ii) a test case that partially succeeds on the master will also
# partially succeed on the slave.
#
# - The revoke statement that partially succeeds tries to revoke
# an EXECUTE grant for two users, and only one of the user has
# the specific grant. This will cause mysql to drop one of the
# grants and report error for the statement. The slave should
# also drop the grants that the master succeed and the SQL
# thread should not stop on statement failure.
-- echo ######## BUG#49119 #######
-- echo ### i) test case from the 'how to repeat section'
-- source include/master-slave-reset.inc
-- connection master
CREATE TABLE t1(c1 INT);
DELIMITER |;
CREATE PROCEDURE p1() SELECT * FROM t1 |
DELIMITER ;|
-- error ER_NONEXISTING_PROC_GRANT
REVOKE EXECUTE ON PROCEDURE p1 FROM 'root'@'localhost';
-- sync_slave_with_master
-- connection master
DROP TABLE t1;
DROP PROCEDURE p1;
-- sync_slave_with_master
-- echo ### ii) Test case in which REVOKE partially succeeds
-- connection master
-- source include/master-slave-reset.inc
-- connection master
CREATE TABLE t1(c1 INT);
DELIMITER |;
CREATE PROCEDURE p1() SELECT * FROM t1 |
DELIMITER ;|
CREATE USER 'user49119'@'localhost';
GRANT EXECUTE ON PROCEDURE p1 TO 'user49119'@'localhost';
-- echo ##############################################################
-- echo ### Showing grants for both users: root and user49119 (master)
SHOW GRANTS FOR 'user49119'@'localhost';
SHOW GRANTS FOR CURRENT_USER;
-- echo ##############################################################
-- sync_slave_with_master
-- echo ##############################################################
-- echo ### Showing grants for both users: root and user49119 (master)
SHOW GRANTS FOR 'user49119'@'localhost';
SHOW GRANTS FOR CURRENT_USER;
-- echo ##############################################################
-- connection master
-- echo ## This statement will make the revoke fail because root has no
-- echo ## execute grant. However, it will still revoke the grant for
-- echo ## user49119.
-- error ER_NONEXISTING_PROC_GRANT
REVOKE EXECUTE ON PROCEDURE p1 FROM 'user49119'@'localhost', 'root'@'localhost';
-- echo ##############################################################
-- echo ### Showing grants for both users: root and user49119 (master)
-- echo ### after revoke statement failure
SHOW GRANTS FOR 'user49119'@'localhost';
SHOW GRANTS FOR CURRENT_USER;
-- echo ##############################################################
-- sync_slave_with_master
-- echo #############################################################
-- echo ### Showing grants for both users: root and user49119 (slave)
-- echo ### after revoke statement failure (should match
SHOW GRANTS FOR 'user49119'@'localhost';
SHOW GRANTS FOR CURRENT_USER;
-- echo ##############################################################
-- connection master
DROP TABLE t1;
DROP PROCEDURE p1;
DROP USER 'user49119'@'localhost';
-- sync_slave_with_master
--echo "End of test"
......@@ -3378,7 +3378,7 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc,
if (write_to_binlog)
{
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
write_bin_log(thd, FALSE, thd->query(), thd->query_length());
}
rw_unlock(&LOCK_grant);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment