Skip to content

Commit f8c3d59

Browse files
MDEV-26583 SIGSEGV's in spider_get_select_limit_from_select_lex when DELAYED INSERT is used
Spider dereferences a freed select_lex and then results in SIGSEGV.
1 parent e128d85 commit f8c3d59

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

sql/sql_insert.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,11 @@ bool delayed_get_table(THD *thd, MDL_request *grl_protection_request,
24232423
di->table_list.alias.str= di->table_list.table_name.str= di->thd.query();
24242424
di->table_list.alias.length= di->table_list.table_name.length= di->thd.query_length();
24252425
di->table_list.db= di->thd.db;
2426+
/*
2427+
Nulify select_lex because, if the thread that spawned the current one
2428+
disconnects, the select_lex will point to freed memory.
2429+
*/
2430+
di->table_list.select_lex= NULL;
24262431
/*
24272432
We need the tickets so that they can be cloned in
24282433
handle_delayed_insert
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# MDEV-26583 SIGSEGV's in spider_get_select_limit_from_select_lex when DELAYED INSERT is used
3+
#
4+
for master_1
5+
for child2
6+
child2_1
7+
child2_2
8+
child2_3
9+
for child3
10+
connection child2_1;
11+
CREATE DATABASE auto_test_remote;
12+
USE auto_test_remote;
13+
CREATE TABLE tbl_a (
14+
a INT AUTO_INCREMENT KEY,
15+
b INT,INDEX i (b)
16+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
17+
connection master_1;
18+
CREATE DATABASE auto_test_local;
19+
USE auto_test_local;
20+
CREATE TABLE tbl_a (
21+
a INT AUTO_INCREMENT KEY,
22+
b INT,INDEX i (b)
23+
) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='srv "s_2_1", table "tbl_a"';
24+
INSERT DELAYED INTO tbl_a VALUES (0,0),(0,0),(0,0);
25+
connection master_1;
26+
DROP DATABASE auto_test_local;
27+
connection child2_1;
28+
DROP DATABASE auto_test_remote;
29+
for master_1
30+
for child2
31+
child2_1
32+
child2_2
33+
child2_3
34+
for child3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!include include/default_mysqld.cnf
2+
!include ../my_1_1.cnf
3+
!include ../my_2_1.cnf
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--echo #
2+
--echo # MDEV-26583 SIGSEGV's in spider_get_select_limit_from_select_lex when DELAYED INSERT is used
3+
--echo #
4+
5+
--disable_query_log
6+
--disable_result_log
7+
--source ../../t/test_init.inc
8+
--enable_result_log
9+
--enable_query_log
10+
11+
--connection child2_1
12+
CREATE DATABASE auto_test_remote;
13+
USE auto_test_remote;
14+
15+
eval CREATE TABLE tbl_a (
16+
a INT AUTO_INCREMENT KEY,
17+
b INT,INDEX i (b)
18+
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
19+
20+
--connection master_1
21+
CREATE DATABASE auto_test_local;
22+
USE auto_test_local;
23+
24+
eval CREATE TABLE tbl_a (
25+
a INT AUTO_INCREMENT KEY,
26+
b INT,INDEX i (b)
27+
) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='srv "s_2_1", table "tbl_a"';
28+
29+
INSERT DELAYED INTO tbl_a VALUES (0,0),(0,0),(0,0);
30+
31+
let $wait_condition=select count(*)=3 from tbl_a
32+
source include/wait_condition.inc;
33+
34+
--connection master_1
35+
DROP DATABASE auto_test_local;
36+
37+
--connection child2_1
38+
DROP DATABASE auto_test_remote;
39+
40+
--disable_query_log
41+
--disable_result_log
42+
--source ../../t/test_deinit.inc
43+
--enable_result_log
44+
--enable_query_log

0 commit comments

Comments
 (0)