Skip to content
/ server Public

Commit b35af31

Browse files
committed
MDEV-38506: (Regression) Failed GRANT on a procedure breaks replication
Test case to showcase MDEV-38506: A failed GRANT on a procedure will be replicated when sql_mode does not have NO_AUTO_CREATE_USER. This is because the function mysql_routine_grant() does not check if an error occured while performing the GRANT on a procedure before binlogging, it simply always binlogs.
1 parent 41b14ef commit b35af31

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

mysql-test/suite/rpl/t/rpl_grant.test

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,47 @@ sync_slave_with_master;
3434
SELECT user,host FROM mysql.user WHERE user like 'dummy%';
3535
SELECT COUNT(*) FROM mysql.user WHERE user like 'dummy%';
3636

37+
--echo #
38+
--echo # MDEV-38506: Failed GRANT on a procedure breaks replication
39+
--echo #
40+
41+
--echo # Disable NO_AUTO_CREATE_USER so grant will auto-create users
42+
connection master;
43+
SET @old_sql_mode= @@GLOBAL.sql_mode;
44+
SET GLOBAL sql_mode='';
45+
46+
--echo # Create new stored procedure for GRANT EXECUTE ON PROCEDURE
47+
CREATE PROCEDURE test.sp() SELECT 1;
48+
49+
--echo # Create a new user with limited privileges to grant sp execution
50+
CREATE USER 'test_user'@'%' IDENTIFIED BY 'somepass';
51+
GRANT EXECUTE ON test.* TO 'test_user'@'%' WITH GRANT OPTION;
52+
connect (con_test_user,localhost,test_user,somepass);
53+
let $old_binlog_gtid= `SELECT @@global.gtid_binlog_pos`; # Tag the GTID before the failed GRANT
54+
error ER_CANT_CREATE_USER_WITH_GRANT;
55+
GRANT EXECUTE ON PROCEDURE test.sp TO 'nonexistentuser'@'';
56+
57+
--echo # Ensuring the failed GRANT is not replicated..
58+
source include/rpl_sync.inc;
59+
connection master;
60+
let $new_binlog_gtid= `SELECT @@global.gtid_binlog_pos`;
61+
if (`SELECT strcmp('$old_binlog_gtid', '$new_binlog_gtid') != 0`)
62+
{
63+
--echo # binlog_gtid_pos before GRANT: $old_binlog_gtid
64+
--echo # binlog_gtid_pos after GRANT: $new_binlog_gtid
65+
--die Failed GRANT was binlogged
66+
}
67+
connection slave;
68+
error ER_NONEXISTING_GRANT;
69+
SHOW GRANTS for 'nonexistentuser'@'';
70+
--echo # ..PASS
71+
72+
connection master;
73+
disconnect con_test_user;
74+
SET GLOBAL sql_mode= @old_sql_mode;
75+
DROP USER test_user@'%';
76+
DROP PROCEDURE test.sp;
77+
--echo # End of MDEV-38506 test case
78+
3779
--source include/rpl_end.inc
80+
--echo # End of rpl_grant.test

0 commit comments

Comments
 (0)