summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSujatha Sivakumar <sujatha.sivakumar@mariadb.com>2019-03-27 12:34:03 +0530
committerSujatha Sivakumar <sujatha.sivakumar@mariadb.com>2019-03-27 12:34:03 +0530
commitf2d549d8dbda1906b3e5ae0c2fa5589f2b9de662 (patch)
tree2221a3ec1ebf2a09d823a28f03cc6119a9d9d7fa
parente8907112790475772b3e5135b58ef95b3fd8ea68 (diff)
downloadmariadb-git-f2d549d8dbda1906b3e5ae0c2fa5589f2b9de662.tar.gz
MDEV-14784: Slave crashes in show_status_array upon running a trigger with
select from I_S Problem: ======== When applier thread tries to access 'variable_name' of INFORMATION_SCHEMA.SESSION_VARIABLES table through triggers, it results in an abnormal exit of slave server. Analysis: ======== At the time of replication of stored routines and triggers, their associated security context will be sent by the master. The applier thread on the slave server will use this information to set the required security context for the execution of stored routines and triggers. This is achieved as follows. ->The stored routine object has a member named 'm_security_ctx' which holds the security context received from master. ->The applier thread's security_ctx is stored into a 'backup' object. ->Set the applier thread's security_ctx to 'm_security_ctx'. ->Upon the completion of stored routine execution restore the original security context of applier thread from the backup. During the above process the 'm_security_ctx' object is not initialized properly. Hence the 'external_user' of 'm_security_ctx' has invalid value for this variable and accessing this variable results in abnormal exit of server. Fix: === Invoke the Security_context::init() call from the constructor of stored routine so that 'm_security_ctx' gets initialized properly.
-rw-r--r--mysql-test/suite/rpl/r/rpl_slave_invalid_external_user.result15
-rw-r--r--mysql-test/suite/rpl/t/rpl_slave_invalid_external_user.test42
-rw-r--r--sql/sp_head.cc1
3 files changed, 58 insertions, 0 deletions
diff --git a/mysql-test/suite/rpl/r/rpl_slave_invalid_external_user.result b/mysql-test/suite/rpl/r/rpl_slave_invalid_external_user.result
new file mode 100644
index 00000000000..29b815420ba
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_slave_invalid_external_user.result
@@ -0,0 +1,15 @@
+include/master-slave.inc
+[connection master]
+CREATE USER test_user@localhost;
+SET PASSWORD FOR test_user@localhost = password('PWD');
+GRANT ALL ON *.* TO test_user@localhost WITH GRANT OPTION;
+connect conn_test,localhost,test_user,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK;
+connection conn_test;
+CREATE TABLE t1 (f1 INT);
+CREATE TABLE t2 (f2 VARCHAR(64));
+CREATE TRIGGER tr_before BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 SELECT variable_name FROM INFORMATION_SCHEMA.SESSION_VARIABLES;
+CREATE DEFINER='root'@'localhost' TRIGGER tr_after AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 SELECT variable_name FROM INFORMATION_SCHEMA.SESSION_VARIABLES;
+INSERT INTO t1 VALUES (1);
+DROP USER 'test_user'@'localhost';
+DROP TABLE t1, t2;
+include/rpl_end.inc
diff --git a/mysql-test/suite/rpl/t/rpl_slave_invalid_external_user.test b/mysql-test/suite/rpl/t/rpl_slave_invalid_external_user.test
new file mode 100644
index 00000000000..5099d7ee49e
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_slave_invalid_external_user.test
@@ -0,0 +1,42 @@
+# ==== Purpose ====
+#
+# Test verifies that when applier thread tries to access 'variable_name' of
+# INFORMATION_SCHEMA.SESSION_VARIABLES table through triggers it successfully
+# retrieves all the session variables.
+#
+# ==== Implementation ====
+#
+# Steps:
+# 0 - Create two tables t1 and t2.
+# 1 - Create a trigger such that it reads the names of all session variables
+# from INFORMATION_SCHEMA.SESSION_VARIABLES table and populates one of the
+# tables.
+# 2 - Do a DML on master and wait for it to be replicated and ensure that
+# slave is in sync with master and it is up and running.
+#
+# ==== References ====
+#
+# MDEV-14784: Slave crashes in show_status_array upon running a trigger with
+# select from I_S
+
+--source include/master-slave.inc
+--source include/have_binlog_format_mixed.inc
+--enable_connect_log
+CREATE USER test_user@localhost;
+SET PASSWORD FOR test_user@localhost = password('PWD');
+GRANT ALL ON *.* TO test_user@localhost WITH GRANT OPTION;
+connect(conn_test,localhost,test_user,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+
+--connection conn_test
+CREATE TABLE t1 (f1 INT);
+CREATE TABLE t2 (f2 VARCHAR(64));
+CREATE TRIGGER tr_before BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 SELECT variable_name FROM INFORMATION_SCHEMA.SESSION_VARIABLES;
+CREATE DEFINER='root'@'localhost' TRIGGER tr_after AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 SELECT variable_name FROM INFORMATION_SCHEMA.SESSION_VARIABLES;
+
+INSERT INTO t1 VALUES (1);
+--disable_connect_log
+# Cleanup
+--connection master
+DROP USER 'test_user'@'localhost';
+DROP TABLE t1, t2;
+--source include/rpl_end.inc
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 14a57914560..fec7f51eaf0 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -563,6 +563,7 @@ sp_head::sp_head()
DBUG_ENTER("sp_head::sp_head");
+ m_security_ctx.init();
m_backpatch.empty();
m_cont_backpatch.empty();
m_lex.empty();