mirror of
https://github.com/MariaDB/server.git
synced 2025-09-02 09:41:40 +03:00
Bug#30882 Dropping a temporary table inside a stored function may cause a server crash
If a stored function that contains a drop temporary table statement is invoked by a create temporary table of the same name may cause a server crash. The problem is that when dropping a table no check is done to ensure that table is not being used by some outer query (or outer statement), potentially leaving the outer query with a reference to a stale (freed) table. The solution is when dropping a temporary table, always check if the table is being used by some outer statement as a temporary table can be dropped inside stored procedures. The check is performed by looking at the TABLE::query_id value for temporary tables. To simplify this check and to solve a bug related to handling of temporary tables in prelocked mode, this patch changes the way in which this member is used to track the fact that table is used/unused. Now we ensure that TABLE::query_id is zero for unused temporary tables (which means that all temporary tables which were used by a statement should be marked as free for reuse after it's execution has been completed).
This commit is contained in:
@@ -2078,10 +2078,6 @@ create function bug20701() returns varchar(25) binary return "test";
|
||||
create function bug20701() returns varchar(25) return "test";
|
||||
drop function bug20701;
|
||||
|
||||
|
||||
--echo End of 5.1 tests
|
||||
|
||||
|
||||
#
|
||||
# Bug#26503 (Illegal SQL exception handler code causes the server to crash)
|
||||
#
|
||||
@@ -2237,10 +2233,78 @@ end|
|
||||
|
||||
--error ER_SP_CANT_SET_AUTOCOMMIT
|
||||
create trigger t1
|
||||
before insert on t2 for each row set password = password('foo');
|
||||
before insert on t2 for each row set password = password('foo');|
|
||||
|
||||
delimiter ;|
|
||||
|
||||
#
|
||||
# Bug#30882 Dropping a temporary table inside a stored function may cause a server crash
|
||||
#
|
||||
|
||||
--disable_warnings
|
||||
drop function if exists f1;
|
||||
drop function if exists f2;
|
||||
drop table if exists t1, t2;
|
||||
--enable_warnings
|
||||
|
||||
delimiter |;
|
||||
create function f1() returns int
|
||||
begin
|
||||
drop temporary table t1;
|
||||
return 1;
|
||||
end|
|
||||
delimiter ;|
|
||||
--error ER_CANT_REOPEN_TABLE
|
||||
create temporary table t1 as select f1();
|
||||
|
||||
delimiter |;
|
||||
create function f2() returns int
|
||||
begin
|
||||
create temporary table t2 as select f1();
|
||||
return 1;
|
||||
end|
|
||||
delimiter ;|
|
||||
--error ER_CANT_REOPEN_TABLE
|
||||
create temporary table t1 as select f2();
|
||||
|
||||
drop function f1;
|
||||
drop function f2;
|
||||
|
||||
delimiter |;
|
||||
create function f1() returns int
|
||||
begin
|
||||
drop temporary table t2,t1;
|
||||
return 1;
|
||||
end|
|
||||
create function f2() returns int
|
||||
begin
|
||||
create temporary table t2 as select f1();
|
||||
return 1;
|
||||
end|
|
||||
delimiter ;|
|
||||
--error ER_CANT_REOPEN_TABLE
|
||||
create temporary table t1 as select f2();
|
||||
|
||||
drop function f1;
|
||||
drop function f2;
|
||||
|
||||
create temporary table t2(a int);
|
||||
select * from t2;
|
||||
delimiter |;
|
||||
create function f2() returns int
|
||||
begin
|
||||
drop temporary table t2;
|
||||
return 1;
|
||||
end|
|
||||
delimiter ;|
|
||||
select f2();
|
||||
|
||||
drop function f2;
|
||||
--error ER_BAD_TABLE_ERROR
|
||||
drop table t2;
|
||||
|
||||
--echo End of 5.1 tests
|
||||
|
||||
#
|
||||
# BUG#NNNN: New bug synopsis
|
||||
#
|
||||
|
Reference in New Issue
Block a user