summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <dlenev@mysql.com>2005-08-10 10:31:32 +0400
committerunknown <dlenev@mysql.com>2005-08-10 10:31:32 +0400
commitf6fff55eb01baf5830db23198cd9d0c2bdeb4bb5 (patch)
treec88db3649fdcba130d7af9b97d86210c4c5ed3da
parent2b41471429d9db41d64bfb214e29ba57cb3db381 (diff)
downloadmariadb-git-f6fff55eb01baf5830db23198cd9d0c2bdeb4bb5.tar.gz
Fix for bug #12280 "Triggers: crash if flush tables".
We should not allow FLUSH statement to be executed inside both triggers and stored functions. mysql-test/r/sp-error.result: Updated test after replacing error, which is thrown when one uses FLUSH statement inside of stored function, with more specific. Also now we issue more general error when we barking about USE command in stored routines. mysql-test/r/trigger.result: Added test for bug #12280 "Triggers: crash if flush tables" mysql-test/t/sp-error.test: Updated test after replacing error, which is thrown when one uses FLUSH statement inside of stored function, with more specific. Also now we issue more general error when we barking about USE command in stored routines. mysql-test/t/trigger.test: Added test for bug #12280 "Triggers: crash if flush tables" sql/share/errmsg.txt: Removed ER_SP_NO_USE error. Now we use more general ER_SP_BADSTATEMENT in this case. Instead added error message for barking about statements which should not be allowed inside of stored functions or triggers. It is safe to do this since it is highly unprobable that someone will upgrade first to the new 5.0 release and then downgrade back to the old one. sql/sql_parse.cc: reload_acl_and_cache(): FLUSH TABLES and FLUSH PRIVILEGES should not be allowed if we are inside of stored function or trigger. sql/sql_yacc.yy: We should not allow FLUSH statement inside both triggers and stored functions. Replaced error which is thrown in this case with more specific. Also now we issue more general ER_SP_BADSTATEMENT error when one tries to use USE command inside of stored routine.
-rw-r--r--mysql-test/r/sp-error.result4
-rw-r--r--mysql-test/r/trigger.result16
-rw-r--r--mysql-test/t/sp-error.test4
-rw-r--r--mysql-test/t/trigger.test20
-rw-r--r--sql/share/errmsg.txt4
-rw-r--r--sql/sql_parse.cc7
-rw-r--r--sql/sql_yacc.yy11
7 files changed, 57 insertions, 9 deletions
diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result
index 13f46e507ba..bd383379abc 100644
--- a/mysql-test/r/sp-error.result
+++ b/mysql-test/r/sp-error.result
@@ -247,7 +247,7 @@ end|
ERROR 42000: Duplicate cursor: c
create procedure u()
use sptmp|
-ERROR 42000: USE is not allowed in a stored procedure
+ERROR 0A000: USE is not allowed in stored procedures
create procedure p()
begin
declare c cursor for select * from t1;
@@ -616,7 +616,7 @@ begin
flush tables;
return 5;
end|
-ERROR 0A000: FLUSH is not allowed in stored procedures
+ERROR 0A000: FLUSH is not allowed in stored function or trigger
create procedure bug9529_90123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123()
begin
end|
diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result
index 52bf307a686..284e4c1556b 100644
--- a/mysql-test/r/trigger.result
+++ b/mysql-test/r/trigger.result
@@ -2,6 +2,7 @@ drop table if exists t1, t2, t3;
drop view if exists v1;
drop database if exists mysqltest;
drop function if exists f1;
+drop procedure if exists p1;
create table t1 (i int);
create trigger trg before insert on t1 for each row set @a:=1;
set @a:=0;
@@ -635,3 +636,18 @@ show triggers;
Trigger Event Table Statement Timing Created sql_mode
t1_bi INSERT t1 set new.a = '2004-01-00' BEFORE #
drop table t1;
+create table t1 (id int);
+create trigger t1_ai after insert on t1 for each row flush tables;
+ERROR 0A000: FLUSH is not allowed in stored function or trigger
+create trigger t1_ai after insert on t1 for each row flush privileges;
+ERROR 0A000: FLUSH is not allowed in stored function or trigger
+create procedure p1() flush tables;
+create trigger t1_ai after insert on t1 for each row call p1();
+insert into t1 values (0);
+ERROR 0A000: FLUSH is not allowed in stored function or trigger
+drop procedure p1;
+create procedure p1() flush privileges;
+insert into t1 values (0);
+ERROR 0A000: FLUSH is not allowed in stored function or trigger
+drop procedure p1;
+drop table t1;
diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
index 7f567449311..349bd148814 100644
--- a/mysql-test/t/sp-error.test
+++ b/mysql-test/t/sp-error.test
@@ -334,7 +334,7 @@ begin
end|
# USE is not allowed
---error 1336
+--error ER_SP_BADSTATEMENT
create procedure u()
use sptmp|
@@ -885,7 +885,7 @@ create procedure bug10537()
--disable_warnings
drop function if exists bug8409|
--enable_warnings
---error ER_SP_BADSTATEMENT
+--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
create function bug8409()
returns int
begin
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
index 7bf8b1a4e2b..789405696c2 100644
--- a/mysql-test/t/trigger.test
+++ b/mysql-test/t/trigger.test
@@ -7,6 +7,7 @@ drop table if exists t1, t2, t3;
drop view if exists v1;
drop database if exists mysqltest;
drop function if exists f1;
+drop procedure if exists p1;
--enable_warnings
create table t1 (i int);
@@ -642,3 +643,22 @@ show create table t1;
--replace_column 6 #
show triggers;
drop table t1;
+
+# Test for bug #12280 "Triggers: crash if flush tables"
+# FLUSH TABLES and FLUSH PRIVILEGES should be disallowed inside
+# of functions and triggers.
+create table t1 (id int);
+--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
+create trigger t1_ai after insert on t1 for each row flush tables;
+--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
+create trigger t1_ai after insert on t1 for each row flush privileges;
+create procedure p1() flush tables;
+create trigger t1_ai after insert on t1 for each row call p1();
+--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
+insert into t1 values (0);
+drop procedure p1;
+create procedure p1() flush privileges;
+--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
+insert into t1 values (0);
+drop procedure p1;
+drop table t1;
diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt
index 5dd5cd9c775..dd9cbd8d500 100644
--- a/sql/share/errmsg.txt
+++ b/sql/share/errmsg.txt
@@ -5137,8 +5137,8 @@ ER_SP_CANT_ALTER
eng "Failed to ALTER %s %s"
ER_SP_SUBSELECT_NYI 0A000
eng "Subselect value not supported"
-ER_SP_NO_USE 42000
- eng "USE is not allowed in a stored procedure"
+ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 0A000
+ eng "%s is not allowed in stored function or trigger"
ER_SP_VARCOND_AFTER_CURSHNDLR 42000
eng "Variable or condition declaration after cursor or handler declaration"
ER_SP_CURSOR_AFTER_HANDLER 42000
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 677b3a98174..885bf63cb2d 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -6395,6 +6395,13 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
bool result=0;
select_errors=0; /* Write if more errors */
bool tmp_write_to_binlog= 1;
+
+ if (thd->in_sub_stmt)
+ {
+ my_error(ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0), "FLUSH");
+ return 1;
+ }
+
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (options & REFRESH_GRANT)
{
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index b680787b9a3..849987a267c 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1960,7 +1960,7 @@ sp_proc_stmt:
}
if (lex->sql_command == SQLCOM_CHANGE_DB)
{ /* "USE db" doesn't work in a procedure */
- my_message(ER_SP_NO_USE, ER(ER_SP_NO_USE), MYF(0));
+ my_error(ER_SP_BADSTATEMENT, MYF(0), "USE");
YYABORT;
}
/*
@@ -6642,9 +6642,14 @@ flush:
FLUSH_SYM opt_no_write_to_binlog
{
LEX *lex=Lex;
- if (lex->sphead && lex->sphead->m_type == TYPE_ENUM_FUNCTION)
+ if (lex->sphead && lex->sphead->m_type != TYPE_ENUM_PROCEDURE)
{
- my_error(ER_SP_BADSTATEMENT, MYF(0), "FLUSH");
+ /*
+ Note that both FLUSH TABLES and FLUSH PRIVILEGES will break
+ execution in prelocked mode. So it is better to disable
+ FLUSH in stored functions and triggers completely.
+ */
+ my_error(ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0), "FLUSH");
YYABORT;
}
lex->sql_command= SQLCOM_FLUSH; lex->type=0;