Skip to content

Commit 8519255

Browse files
committed
MDEV-24560 SIGSEGV in st_join_table::cleanup
If JOIN::create_postjoin_aggr_table encounters errors during execution then free_tmp_table() is then called twice for JOIN_TAB::aggr. The solution is to initialize JOIN_TAB::aggr only on successful completion of JOIN::create_postjoin_aggr_table
1 parent 75b9014 commit 8519255

File tree

5 files changed

+116
-7
lines changed

5 files changed

+116
-7
lines changed

mysql-test/r/select.result

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5548,4 +5548,31 @@ select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined));
55485548
(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined))
55495549
NULL
55505550
drop table t1;
5551+
#
5552+
# Bug MDEV-24262 Server crashes in st_join_table::cleanup upon
5553+
# erroneous GROUP_CONCAT
5554+
#
5555+
CREATE TABLE t1 (a INT, b INT);
5556+
INSERT INTO t1 VALUES (1,10),(2,20);
5557+
SELECT b, GROUP_CONCAT(b ORDER BY 2), MIN(a) AS f FROM t1 GROUP BY b ORDER BY f;
5558+
ERROR 42S22: Unknown column '2' in 'order clause'
5559+
DROP TABLE t1;
5560+
#
5561+
# Bug MDEV-24560 SIGSEGV in st_join_table::cleanup + server and client
5562+
# hang + cross-mysqld-interaction + double free or corruption (!prev)
5563+
#
5564+
CREATE TABLE t1 (c INT);
5565+
SET SESSION sql_buffer_result=1;
5566+
SELECT GROUP_CONCAT(c ORDER BY 2) FROM t1;
5567+
GROUP_CONCAT(c ORDER BY 2)
5568+
NULL
5569+
SELECT GROUP_CONCAT(c ORDER BY 0) FROM t1;
5570+
GROUP_CONCAT(c ORDER BY 0)
5571+
NULL
5572+
DROP TABLE t1;
5573+
CREATE TABLE t1 (grp INT,c CHAR);
5574+
SET sql_buffer_result=1;
5575+
SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp;
5576+
grp GROUP_CONCAT(c ORDER BY 2)
5577+
DROP TABLE t1;
55515578
End of 10.0 tests

mysql-test/r/select_jcl6.result

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5559,6 +5559,33 @@ select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined));
55595559
(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined))
55605560
NULL
55615561
drop table t1;
5562+
#
5563+
# Bug MDEV-24262 Server crashes in st_join_table::cleanup upon
5564+
# erroneous GROUP_CONCAT
5565+
#
5566+
CREATE TABLE t1 (a INT, b INT);
5567+
INSERT INTO t1 VALUES (1,10),(2,20);
5568+
SELECT b, GROUP_CONCAT(b ORDER BY 2), MIN(a) AS f FROM t1 GROUP BY b ORDER BY f;
5569+
ERROR 42S22: Unknown column '2' in 'order clause'
5570+
DROP TABLE t1;
5571+
#
5572+
# Bug MDEV-24560 SIGSEGV in st_join_table::cleanup + server and client
5573+
# hang + cross-mysqld-interaction + double free or corruption (!prev)
5574+
#
5575+
CREATE TABLE t1 (c INT);
5576+
SET SESSION sql_buffer_result=1;
5577+
SELECT GROUP_CONCAT(c ORDER BY 2) FROM t1;
5578+
GROUP_CONCAT(c ORDER BY 2)
5579+
NULL
5580+
SELECT GROUP_CONCAT(c ORDER BY 0) FROM t1;
5581+
GROUP_CONCAT(c ORDER BY 0)
5582+
NULL
5583+
DROP TABLE t1;
5584+
CREATE TABLE t1 (grp INT,c CHAR);
5585+
SET sql_buffer_result=1;
5586+
SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp;
5587+
grp GROUP_CONCAT(c ORDER BY 2)
5588+
DROP TABLE t1;
55625589
End of 10.0 tests
55635590
set join_cache_level=default;
55645591
set @@optimizer_switch=@save_optimizer_switch_jcl6;

mysql-test/r/select_pkeycache.result

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5548,4 +5548,31 @@ select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined));
55485548
(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined))
55495549
NULL
55505550
drop table t1;
5551+
#
5552+
# Bug MDEV-24262 Server crashes in st_join_table::cleanup upon
5553+
# erroneous GROUP_CONCAT
5554+
#
5555+
CREATE TABLE t1 (a INT, b INT);
5556+
INSERT INTO t1 VALUES (1,10),(2,20);
5557+
SELECT b, GROUP_CONCAT(b ORDER BY 2), MIN(a) AS f FROM t1 GROUP BY b ORDER BY f;
5558+
ERROR 42S22: Unknown column '2' in 'order clause'
5559+
DROP TABLE t1;
5560+
#
5561+
# Bug MDEV-24560 SIGSEGV in st_join_table::cleanup + server and client
5562+
# hang + cross-mysqld-interaction + double free or corruption (!prev)
5563+
#
5564+
CREATE TABLE t1 (c INT);
5565+
SET SESSION sql_buffer_result=1;
5566+
SELECT GROUP_CONCAT(c ORDER BY 2) FROM t1;
5567+
GROUP_CONCAT(c ORDER BY 2)
5568+
NULL
5569+
SELECT GROUP_CONCAT(c ORDER BY 0) FROM t1;
5570+
GROUP_CONCAT(c ORDER BY 0)
5571+
NULL
5572+
DROP TABLE t1;
5573+
CREATE TABLE t1 (grp INT,c CHAR);
5574+
SET sql_buffer_result=1;
5575+
SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp;
5576+
grp GROUP_CONCAT(c ORDER BY 2)
5577+
DROP TABLE t1;
55515578
End of 10.0 tests

mysql-test/t/select.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,4 +4670,32 @@ select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined));
46704670

46714671
drop table t1;
46724672

4673+
--echo #
4674+
--echo # Bug MDEV-24262 Server crashes in st_join_table::cleanup upon
4675+
--echo # erroneous GROUP_CONCAT
4676+
--echo #
4677+
4678+
CREATE TABLE t1 (a INT, b INT);
4679+
INSERT INTO t1 VALUES (1,10),(2,20);
4680+
--error ER_BAD_FIELD_ERROR
4681+
SELECT b, GROUP_CONCAT(b ORDER BY 2), MIN(a) AS f FROM t1 GROUP BY b ORDER BY f;
4682+
4683+
DROP TABLE t1;
4684+
4685+
--echo #
4686+
--echo # Bug MDEV-24560 SIGSEGV in st_join_table::cleanup + server and client
4687+
--echo # hang + cross-mysqld-interaction + double free or corruption (!prev)
4688+
--echo #
4689+
4690+
CREATE TABLE t1 (c INT);
4691+
SET SESSION sql_buffer_result=1;
4692+
SELECT GROUP_CONCAT(c ORDER BY 2) FROM t1;
4693+
SELECT GROUP_CONCAT(c ORDER BY 0) FROM t1;
4694+
DROP TABLE t1;
4695+
4696+
CREATE TABLE t1 (grp INT,c CHAR);
4697+
SET sql_buffer_result=1;
4698+
SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp;
4699+
DROP TABLE t1;
4700+
46734701
--echo End of 10.0 tests

sql/sql_select.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,14 +2989,11 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
29892989
tmp_table_param.using_outer_summary_function=
29902990
tab->tmp_table_param->using_outer_summary_function;
29912991
tab->join= this;
2992-
DBUG_ASSERT(tab > tab->join->join_tab || !top_join_tab_count || !tables_list);
2992+
DBUG_ASSERT(tab > tab->join->join_tab || !top_join_tab_count ||
2993+
!tables_list);
2994+
tab->table= table;
29932995
if (tab > join_tab)
29942996
(tab - 1)->next_select= sub_select_postjoin_aggr;
2995-
tab->aggr= new (thd->mem_root) AGGR_OP(tab);
2996-
if (!tab->aggr)
2997-
goto err;
2998-
tab->table= table;
2999-
table->reginfo.join_tab= tab;
30002997

30012998
/* if group or order on first table, sort first */
30022999
if ((group_list && simple_group) ||
@@ -3047,12 +3044,15 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields,
30473044
order= NULL;
30483045
}
30493046
}
3050-
3047+
if (!(tab->aggr= new (thd->mem_root) AGGR_OP(tab)))
3048+
goto err;
3049+
table->reginfo.join_tab= tab;
30513050
DBUG_RETURN(false);
30523051

30533052
err:
30543053
if (table != NULL)
30553054
free_tmp_table(thd, table);
3055+
tab->table= NULL;
30563056
DBUG_RETURN(true);
30573057
}
30583058

0 commit comments

Comments
 (0)