Skip to content

Commit 5615a78

Browse files
committed
MDEV-28266 Crash in Field_string::type_handler when calling procedures
on_table_fill_finished() should always be done at the end of open() even if result is not Select_materialize but (for example) Select_fetch_into_spvars.
1 parent cdc0bbd commit 5615a78

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

mysql-test/main/sp-cursor.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,3 +800,15 @@ drop procedure test_proc;
800800
drop view v1;
801801
drop function get_name;
802802
drop table t1;
803+
#
804+
# MDEV-28266: Crash in Field_string::type_handler when calling procedures
805+
#
806+
CREATE TABLE t (f INT);
807+
CREATE TRIGGER tr AFTER INSERT ON t FOR EACH ROW
808+
FOR x IN (SELECT * FROM json_table(NULL, '$' COLUMNS(a CHAR(1) path '$.*')) tmp)
809+
DO set @a=1; END FOR $
810+
INSERT INTO t () values ();
811+
DROP TABLE t;
812+
#
813+
# End of 10.6 tests
814+
#

mysql-test/main/sp-cursor.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,3 +800,24 @@ drop procedure test_proc;
800800
drop view v1;
801801
drop function get_name;
802802
drop table t1;
803+
804+
--echo #
805+
--echo # MDEV-28266: Crash in Field_string::type_handler when calling procedures
806+
--echo #
807+
808+
CREATE TABLE t (f INT);
809+
810+
--delimiter $
811+
CREATE TRIGGER tr AFTER INSERT ON t FOR EACH ROW
812+
FOR x IN (SELECT * FROM json_table(NULL, '$' COLUMNS(a CHAR(1) path '$.*')) tmp)
813+
DO set @a=1; END FOR $
814+
--delimiter ;
815+
816+
INSERT INTO t () values ();
817+
818+
# Cleanup
819+
DROP TABLE t;
820+
821+
--echo #
822+
--echo # End of 10.6 tests
823+
--echo #

sql/sql_cursor.cc

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,7 @@ class Select_materialize: public select_unit
8080
Select_materialize(THD *thd_arg, select_result *result_arg):
8181
select_unit(thd_arg), result(result_arg), materialized_cursor(0) {}
8282
virtual bool send_result_set_metadata(List<Item> &list, uint flags);
83-
bool send_eof()
84-
{
85-
if (materialized_cursor)
86-
materialized_cursor->on_table_fill_finished();
87-
return false;
88-
}
89-
90-
void abort_result_set()
91-
{
92-
if (materialized_cursor)
93-
materialized_cursor->on_table_fill_finished();
94-
}
95-
83+
bool send_eof() { return false; }
9684
bool view_structure_only() const
9785
{
9886
return result->view_structure_only();
@@ -333,6 +321,8 @@ int Materialized_cursor::open(JOIN *join __attribute__((unused)))
333321
result->abort_result_set();
334322
}
335323

324+
on_table_fill_finished();
325+
336326
return rc;
337327
}
338328

0 commit comments

Comments
 (0)