[Commits] 6516941: MDEV-15940 Crash when using CURSOR with VALUES()

IgorBabaev igor at mariadb.com
Sun Apr 22 03:20:20 EEST 2018


revision-id: 65169418c5128fb8398ac356d93262ae9549a98c (mariadb-10.3.6-29-g6516941)
parent(s): c058117c6c857ecb41960bd705104adc42348645
author: Igor Babaev
committer: Igor Babaev
timestamp: 2018-04-21 17:20:20 -0700
message:

MDEV-15940 Crash when using CURSOR with VALUES()

The function st_select_lex_unit::get_column_types() should
take into account that a unit may contain only a table
value constructor and nothing more.

---
 mysql-test/main/table_value_constr.result | 21 +++++++++++++++++++++
 mysql-test/main/table_value_constr.test   | 24 ++++++++++++++++++++++++
 sql/sql_union.cc                          |  2 +-
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/mysql-test/main/table_value_constr.result b/mysql-test/main/table_value_constr.result
index 39caba3..5a904cb 100644
--- a/mysql-test/main/table_value_constr.result
+++ b/mysql-test/main/table_value_constr.result
@@ -2071,3 +2071,24 @@ ERROR HY000: Field reference 'b' can't be used in table value constructor
 select * from (values (1), (t1.b), (2)) as new_tvc;
 ERROR HY000: Field reference 't1.b' can't be used in table value constructor
 drop table t1;
+#
+# MDEV-MDEV-15940: cursor over TVC
+#
+BEGIN NOT ATOMIC
+DECLARE v INT;
+DECLARE cur CURSOR FOR VALUES(7);
+OPEN cur;
+FETCH cur INTO v;
+SELECT v;
+END;
+|
+v
+7
+BEGIN NOT ATOMIC
+DECLARE v INT DEFAULT 0;
+FOR a IN (VALUES (7)) DO SET v = v + 1; END FOR;
+SELECT v;
+END;
+|
+v
+1
diff --git a/mysql-test/main/table_value_constr.test b/mysql-test/main/table_value_constr.test
index 578f894..84f196b 100644
--- a/mysql-test/main/table_value_constr.test
+++ b/mysql-test/main/table_value_constr.test
@@ -1044,3 +1044,27 @@ select * from (values (1), (b), (2)) as new_tvc;
 select * from (values (1), (t1.b), (2)) as new_tvc;
 
 drop table t1;
+
+--echo #
+--echo # MDEV-MDEV-15940: cursor over TVC
+--echo #
+
+DELIMITER |;
+
+BEGIN NOT ATOMIC
+  DECLARE v INT;
+  DECLARE cur CURSOR FOR VALUES(7);
+  OPEN cur;
+  FETCH cur INTO v;
+  SELECT v;
+END;
+|
+
+BEGIN NOT ATOMIC
+DECLARE v INT DEFAULT 0;
+FOR a IN (VALUES (7)) DO SET v = v + 1; END FOR;
+SELECT v;
+END;
+|
+
+DELIMITER ;|
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 4cc7de8..432ad85 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -1874,7 +1874,7 @@ bool st_select_lex_unit::change_result(select_result_interceptor *new_result,
 List<Item> *st_select_lex_unit::get_column_types(bool for_cursor)
 {
   SELECT_LEX *sl= first_select();
-  bool is_procedure= MY_TEST(sl->join->procedure);
+  bool is_procedure= !sl->tvc && sl->join->procedure ;
 
   if (is_procedure)
   {


More information about the commits mailing list