Skip to content

Commit f2d549d

Browse files
committed
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.
1 parent e890711 commit f2d549d

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include/master-slave.inc
2+
[connection master]
3+
CREATE USER test_user@localhost;
4+
SET PASSWORD FOR test_user@localhost = password('PWD');
5+
GRANT ALL ON *.* TO test_user@localhost WITH GRANT OPTION;
6+
connect conn_test,localhost,test_user,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK;
7+
connection conn_test;
8+
CREATE TABLE t1 (f1 INT);
9+
CREATE TABLE t2 (f2 VARCHAR(64));
10+
CREATE TRIGGER tr_before BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 SELECT variable_name FROM INFORMATION_SCHEMA.SESSION_VARIABLES;
11+
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;
12+
INSERT INTO t1 VALUES (1);
13+
DROP USER 'test_user'@'localhost';
14+
DROP TABLE t1, t2;
15+
include/rpl_end.inc
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# ==== Purpose ====
2+
#
3+
# Test verifies that when applier thread tries to access 'variable_name' of
4+
# INFORMATION_SCHEMA.SESSION_VARIABLES table through triggers it successfully
5+
# retrieves all the session variables.
6+
#
7+
# ==== Implementation ====
8+
#
9+
# Steps:
10+
# 0 - Create two tables t1 and t2.
11+
# 1 - Create a trigger such that it reads the names of all session variables
12+
# from INFORMATION_SCHEMA.SESSION_VARIABLES table and populates one of the
13+
# tables.
14+
# 2 - Do a DML on master and wait for it to be replicated and ensure that
15+
# slave is in sync with master and it is up and running.
16+
#
17+
# ==== References ====
18+
#
19+
# MDEV-14784: Slave crashes in show_status_array upon running a trigger with
20+
# select from I_S
21+
22+
--source include/master-slave.inc
23+
--source include/have_binlog_format_mixed.inc
24+
--enable_connect_log
25+
CREATE USER test_user@localhost;
26+
SET PASSWORD FOR test_user@localhost = password('PWD');
27+
GRANT ALL ON *.* TO test_user@localhost WITH GRANT OPTION;
28+
connect(conn_test,localhost,test_user,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
29+
30+
--connection conn_test
31+
CREATE TABLE t1 (f1 INT);
32+
CREATE TABLE t2 (f2 VARCHAR(64));
33+
CREATE TRIGGER tr_before BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 SELECT variable_name FROM INFORMATION_SCHEMA.SESSION_VARIABLES;
34+
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;
35+
36+
INSERT INTO t1 VALUES (1);
37+
--disable_connect_log
38+
# Cleanup
39+
--connection master
40+
DROP USER 'test_user'@'localhost';
41+
DROP TABLE t1, t2;
42+
--source include/rpl_end.inc

sql/sp_head.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ sp_head::sp_head()
563563

564564
DBUG_ENTER("sp_head::sp_head");
565565

566+
m_security_ctx.init();
566567
m_backpatch.empty();
567568
m_cont_backpatch.empty();
568569
m_lex.empty();

0 commit comments

Comments
 (0)