summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2020-07-24 09:59:38 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2020-07-28 08:23:57 +0200
commitc6eb21cd878f8762b3abb12813403ed8e04fee0c (patch)
treea2244289439f6ff98576a85d34259f4166b7c192
parentfd9ca2a742abe2e91b2b77e70915dec7bd3cd7e1 (diff)
downloadmariadb-git-c6eb21cd878f8762b3abb12813403ed8e04fee0c.tar.gz
MDEV-21998: Server crashes in st_select_lex::add_table_to_list upon mix of KILL and sequences
Continue support the hack of current select equal builtin select if selects stack is empty even after subselects.
-rw-r--r--mysql-test/main/parser.result8
-rw-r--r--mysql-test/main/parser.test8
-rw-r--r--mysql-test/main/signal.result6
-rw-r--r--mysql-test/main/signal.test6
-rw-r--r--mysql-test/main/sp-error.result4
-rw-r--r--mysql-test/main/sp-error.test4
-rw-r--r--mysql-test/main/sp.result18
-rw-r--r--mysql-test/main/sp.test18
-rw-r--r--mysql-test/suite/compat/oracle/r/sp-cursor-rowtype.result2
-rw-r--r--mysql-test/suite/compat/oracle/r/sp.result8
-rw-r--r--mysql-test/suite/compat/oracle/t/sp-cursor-rowtype.test2
-rw-r--r--mysql-test/suite/compat/oracle/t/sp.test8
-rw-r--r--sql/sql_lex.cc14
-rw-r--r--sql/sql_lex.h5
14 files changed, 67 insertions, 44 deletions
diff --git a/mysql-test/main/parser.result b/mysql-test/main/parser.result
index ad22cd886f7..37f510c8ce3 100644
--- a/mysql-test/main/parser.result
+++ b/mysql-test/main/parser.result
@@ -1893,4 +1893,12 @@ i
1
i
2
+#
+# MDEV-21998: Server crashes in st_select_lex::add_table_to_list
+# upon mix of KILL and sequences
+#
+KILL ( SELECT 1 ) + LASTVAL(s);
+ERROR 42000: KILL does not support subqueries or stored functions
+KILL LASTVAL(s);
+ERROR 42000: KILL does not support subqueries or stored functions
# End of 10.4 tests
diff --git a/mysql-test/main/parser.test b/mysql-test/main/parser.test
index 09fe73b7dbe..b8ea7bd22e4 100644
--- a/mysql-test/main/parser.test
+++ b/mysql-test/main/parser.test
@@ -1677,6 +1677,14 @@ $$
DELIMITER ;$$
+--echo #
+--echo # MDEV-21998: Server crashes in st_select_lex::add_table_to_list
+--echo # upon mix of KILL and sequences
+--echo #
+--error ER_SUBQUERIES_NOT_SUPPORTED
+KILL ( SELECT 1 ) + LASTVAL(s);
+--error ER_SUBQUERIES_NOT_SUPPORTED
+KILL LASTVAL(s);
--echo # End of 10.4 tests
diff --git a/mysql-test/main/signal.result b/mysql-test/main/signal.result
index 40b1609fc26..b5b479db017 100644
--- a/mysql-test/main/signal.result
+++ b/mysql-test/main/signal.result
@@ -2285,13 +2285,13 @@ begin
DECLARE foo CONDITION FOR SQLSTATE '12345';
SIGNAL foo SET MYSQL_ERRNO = `65`; /* illegal */
end $$
-ERROR 42S22: Unknown column '65' in 'field list'
+ERROR 42000: Undeclared variable: 65
create procedure test_signal()
begin
DECLARE foo CONDITION FOR SQLSTATE '12345';
SIGNAL foo SET MYSQL_ERRNO = `A`; /* illegal */
end $$
-ERROR 42S22: Unknown column 'A' in 'field list'
+ERROR 42000: Undeclared variable: A
create procedure test_signal()
begin
DECLARE foo CONDITION FOR SQLSTATE '12345';
@@ -2342,7 +2342,7 @@ DECLARE foo CONDITION FOR SQLSTATE '12345';
SIGNAL foo SET MYSQL_ERRNO = 1000,
MESSAGE_TEXT = `Hello`;
end $$
-ERROR 42S22: Unknown column 'Hello' in 'field list'
+ERROR 42000: Undeclared variable: Hello
create procedure test_signal()
begin
DECLARE foo CONDITION FOR SQLSTATE '12345';
diff --git a/mysql-test/main/signal.test b/mysql-test/main/signal.test
index 5b40863b0e6..22cfc080895 100644
--- a/mysql-test/main/signal.test
+++ b/mysql-test/main/signal.test
@@ -2546,7 +2546,7 @@ end $$
call test_signal $$
drop procedure test_signal $$
--- error ER_BAD_FIELD_ERROR
+-- error ER_SP_UNDECLARED_VAR
create procedure test_signal()
begin
DECLARE foo CONDITION FOR SQLSTATE '12345';
@@ -2554,7 +2554,7 @@ begin
end $$
--- error ER_BAD_FIELD_ERROR
+-- error ER_SP_UNDECLARED_VAR
create procedure test_signal()
begin
DECLARE foo CONDITION FOR SQLSTATE '12345';
@@ -2616,7 +2616,7 @@ end $$
call test_signal $$
drop procedure test_signal $$
--- error ER_BAD_FIELD_ERROR
+-- error ER_SP_UNDECLARED_VAR
create procedure test_signal()
begin
DECLARE foo CONDITION FOR SQLSTATE '12345';
diff --git a/mysql-test/main/sp-error.result b/mysql-test/main/sp-error.result
index d77928fcf5e..1fe5bd6b77b 100644
--- a/mysql-test/main/sp-error.result
+++ b/mysql-test/main/sp-error.result
@@ -454,7 +454,7 @@ else
set b = a;
end if;
end|
-ERROR 42S22: Unknown column 'aa' in 'field list'
+ERROR 42000: Undeclared variable: aa
create procedure bug4344() drop procedure bug4344|
ERROR HY000: Can't drop or alter a PROCEDURE from within another stored routine
create procedure bug4344() drop function bug4344|
@@ -1069,7 +1069,7 @@ IF bug13037_foo THEN
SELECT 1;
END IF;
END|
-ERROR 42S22: Unknown column 'bug13037_foo' in 'field list'
+ERROR 42000: Undeclared variable: bug13037_foo
CREATE PROCEDURE bug13037_p2()
BEGIN
SET @bug13037_foo = bug13037_bar;
diff --git a/mysql-test/main/sp-error.test b/mysql-test/main/sp-error.test
index 4b2169aad94..45a54fddad4 100644
--- a/mysql-test/main/sp-error.test
+++ b/mysql-test/main/sp-error.test
@@ -615,7 +615,7 @@ call bug2653_1(1, @b)|
drop procedure bug2653_1|
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
create procedure bug2653_2(a int, out b int)
begin
if aa < 0 then
@@ -1508,7 +1508,7 @@ DROP PROCEDURE IF EXISTS bug13037_p3;
delimiter |;
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE bug13037_p1()
BEGIN
IF bug13037_foo THEN
diff --git a/mysql-test/main/sp.result b/mysql-test/main/sp.result
index 376f44e3b01..d40516da88e 100644
--- a/mysql-test/main/sp.result
+++ b/mysql-test/main/sp.result
@@ -4186,7 +4186,7 @@ select v, isnull(v);
end if;
end;
end|
-ERROR 42S22: Unknown column 'undefined_var' in 'field list'
+ERROR 42000: Undeclared variable: undefined_var
create procedure bug14643_2()
begin
declare continue handler for sqlexception select 'boo' as 'Handler';
@@ -4198,7 +4198,7 @@ select 2;
end case;
select undefined_var;
end|
-ERROR 42S22: Unknown column 'undefined_var' in 'field list'
+ERROR 42000: Undeclared variable: undefined_var
drop procedure if exists bug14304|
drop table if exists t3, t4|
create table t3(a int primary key auto_increment)|
@@ -4228,7 +4228,7 @@ create procedure bug14376()
begin
declare x int default x;
end|
-ERROR 42S22: Unknown column 'x' in 'field list'
+ERROR 42000: Undeclared variable: x
create procedure bug14376()
begin
declare x int default 42;
@@ -4483,7 +4483,7 @@ select 'no' as 'v';
end if;
select 'done' as 'End';
end|
-ERROR 42S22: Unknown column 'v' in 'field list'
+ERROR 42000: Undeclared variable: v
create procedure bug14498_2()
begin
declare continue handler for sqlexception select 'error' as 'Handler';
@@ -4492,7 +4492,7 @@ select 'yes' as 'v';
end while;
select 'done' as 'End';
end|
-ERROR 42S22: Unknown column 'v' in 'field list'
+ERROR 42000: Undeclared variable: v
create procedure bug14498_3()
begin
declare continue handler for sqlexception select 'error' as 'Handler';
@@ -4501,7 +4501,7 @@ select 'maybe' as 'v';
until v end repeat;
select 'done' as 'End';
end|
-ERROR 42S22: Unknown column 'v' in 'field list'
+ERROR 42000: Undeclared variable: v
create procedure bug14498_4()
begin
declare continue handler for sqlexception select 'error' as 'Handler';
@@ -4515,7 +4515,7 @@ select '?' as 'v';
end case;
select 'done' as 'End';
end|
-ERROR 42S22: Unknown column 'v' in 'field list'
+ERROR 42000: Undeclared variable: v
create procedure bug14498_5()
begin
declare continue handler for sqlexception select 'error' as 'Handler';
@@ -4529,7 +4529,7 @@ select '?' as 'v';
end case;
select 'done' as 'End';
end|
-ERROR 42S22: Unknown column 'v' in 'field list'
+ERROR 42000: Undeclared variable: v
drop table if exists t3|
drop procedure if exists bug15231_1|
drop procedure if exists bug15231_2|
@@ -8403,7 +8403,7 @@ DECLARE name VARCHAR(10);
SET name="hello";
call p1(name2);
END|
-ERROR 42S22: Unknown column 'name2' in 'field list'
+ERROR 42000: Undeclared variable: name2
call p2();
a
hello
diff --git a/mysql-test/main/sp.test b/mysql-test/main/sp.test
index 7d1e8e2a8f9..bddd07bdb6c 100644
--- a/mysql-test/main/sp.test
+++ b/mysql-test/main/sp.test
@@ -5046,7 +5046,7 @@ drop procedure if exists bug14643_1|
drop procedure if exists bug14643_2|
--enable_warnings
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
create procedure bug14643_1()
begin
declare continue handler for sqlexception select 'boo' as 'Handler';
@@ -5062,7 +5062,7 @@ begin
end;
end|
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
create procedure bug14643_2()
begin
declare continue handler for sqlexception select 'boo' as 'Handler';
@@ -5117,7 +5117,7 @@ drop table t3, t4|
drop procedure if exists bug14376|
--enable_warnings
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
create procedure bug14376()
begin
declare x int default x;
@@ -5344,7 +5344,7 @@ drop procedure if exists bug14498_4|
drop procedure if exists bug14498_5|
--enable_warnings
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
create procedure bug14498_1()
begin
declare continue handler for sqlexception select 'error' as 'Handler';
@@ -5357,7 +5357,7 @@ begin
select 'done' as 'End';
end|
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
create procedure bug14498_2()
begin
declare continue handler for sqlexception select 'error' as 'Handler';
@@ -5368,7 +5368,7 @@ begin
select 'done' as 'End';
end|
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
create procedure bug14498_3()
begin
declare continue handler for sqlexception select 'error' as 'Handler';
@@ -5379,7 +5379,7 @@ begin
select 'done' as 'End';
end|
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
create procedure bug14498_4()
begin
declare continue handler for sqlexception select 'error' as 'Handler';
@@ -5395,7 +5395,7 @@ begin
select 'done' as 'End';
end|
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
create procedure bug14498_5()
begin
declare continue handler for sqlexception select 'error' as 'Handler';
@@ -9931,7 +9931,7 @@ BEGIN
call p1(name);
END|
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
CREATE OR REPLACE PROCEDURE p3 ()
BEGIN
DECLARE name VARCHAR(10);
diff --git a/mysql-test/suite/compat/oracle/r/sp-cursor-rowtype.result b/mysql-test/suite/compat/oracle/r/sp-cursor-rowtype.result
index a60bbc38883..31d794c9f61 100644
--- a/mysql-test/suite/compat/oracle/r/sp-cursor-rowtype.result
+++ b/mysql-test/suite/compat/oracle/r/sp-cursor-rowtype.result
@@ -1045,7 +1045,7 @@ NULL;
END LOOP;
END;
$$
-ERROR 42000: Undefined CURSOR: c2
+ERROR 42000: Undeclared variable: c2
# Make sure "rec" shadows other declarations outside the loop
CREATE TABLE t1 (a INT, b VARCHAR(10));
INSERT INTO t1 VALUES (10, 'b0');
diff --git a/mysql-test/suite/compat/oracle/r/sp.result b/mysql-test/suite/compat/oracle/r/sp.result
index 6bcdf520edb..4b360241c01 100644
--- a/mysql-test/suite/compat/oracle/r/sp.result
+++ b/mysql-test/suite/compat/oracle/r/sp.result
@@ -1019,7 +1019,7 @@ LOOP
EXIT WHEN unknown_ident IS NULL;
END LOOP;
END$$
-ERROR 42S22: Unknown column 'unknown_ident' in 'field list'
+ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1
AS
BEGIN
@@ -1028,7 +1028,7 @@ LOOP
EXIT label WHEN unknown_ident IS NULL;
END LOOP;
END$$
-ERROR 42S22: Unknown column 'unknown_ident' in 'field list'
+ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1
AS
BEGIN
@@ -1036,7 +1036,7 @@ LOOP
CONTINUE WHEN unknown_ident IS NULL;
END LOOP;
END$$
-ERROR 42S22: Unknown column 'unknown_ident' in 'field list'
+ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1
AS
BEGIN
@@ -1045,7 +1045,7 @@ LOOP
CONTINUE label WHEN unknown_ident IS NULL;
END LOOP;
END$$
-ERROR 42S22: Unknown column 'unknown_ident' in 'field list'
+ERROR 42000: Undeclared variable: unknown_ident
#
# MDEV-10583 sql_mode=ORACLE: SQL%ROWCOUNT
#
diff --git a/mysql-test/suite/compat/oracle/t/sp-cursor-rowtype.test b/mysql-test/suite/compat/oracle/t/sp-cursor-rowtype.test
index ba0ca9b6a60..78a38c5f4c6 100644
--- a/mysql-test/suite/compat/oracle/t/sp-cursor-rowtype.test
+++ b/mysql-test/suite/compat/oracle/t/sp-cursor-rowtype.test
@@ -1128,7 +1128,7 @@ DELIMITER ;$$
--echo # IN followed by an unknown cursor name
DELIMITER $$;
---error ER_SP_CURSOR_MISMATCH
+--error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE p1 AS
CURSOR c1 IS SELECT 'test' AS a FROM DUAL;
BEGIN
diff --git a/mysql-test/suite/compat/oracle/t/sp.test b/mysql-test/suite/compat/oracle/t/sp.test
index 4fae03b7721..04b9f1be1e2 100644
--- a/mysql-test/suite/compat/oracle/t/sp.test
+++ b/mysql-test/suite/compat/oracle/t/sp.test
@@ -1094,7 +1094,7 @@ DROP FUNCTION f1;
--echo #
DELIMITER $$;
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE p1
AS
BEGIN
@@ -1106,7 +1106,7 @@ DELIMITER ;$$
DELIMITER $$;
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE p1
AS
BEGIN
@@ -1119,7 +1119,7 @@ DELIMITER ;$$
DELIMITER $$;
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE p1
AS
BEGIN
@@ -1131,7 +1131,7 @@ DELIMITER ;$$
DELIMITER $$;
---error ER_BAD_FIELD_ERROR
+--error ER_SP_UNDECLARED_VAR
CREATE PROCEDURE p1
AS
BEGIN
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index c21a5dee088..53e4b020ff6 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -7560,6 +7560,7 @@ Item *LEX::create_item_ident_sp(THD *thd, Lex_ident_sys_st *name,
const Sp_rcontext_handler *rh;
sp_variable *spv;
+ uint unused_off;
DBUG_ASSERT(spcont);
DBUG_ASSERT(sphead);
if ((spv= find_variable(name, &rh)))
@@ -7598,7 +7599,9 @@ Item *LEX::create_item_ident_sp(THD *thd, Lex_ident_sys_st *name,
return new (thd->mem_root) Item_func_sqlerrm(thd);
}
- if (!current_select)
+ if (!select_stack_head() &&
+ (current_select->parsing_place != FOR_LOOP_BOUND ||
+ spcont->find_cursor(name, &unused_off, false) == NULL))
{
// we are out of SELECT or FOR so it is syntax error
my_error(ER_SP_UNDECLARED_VAR, MYF(0), name->str);
@@ -9083,7 +9086,8 @@ Item *LEX::create_item_query_expression(THD *thd,
// Add the subtree of subquery to the current SELECT_LEX
SELECT_LEX *curr_sel= select_stack_head();
- DBUG_ASSERT(current_select == curr_sel);
+ DBUG_ASSERT(current_select == curr_sel ||
+ (curr_sel == NULL && current_select == &builtin_select));
if (!curr_sel)
{
curr_sel= &builtin_select;
@@ -9315,7 +9319,8 @@ SELECT_LEX *LEX::parsed_subselect(SELECT_LEX_UNIT *unit)
// Add the subtree of subquery to the current SELECT_LEX
SELECT_LEX *curr_sel= select_stack_head();
- DBUG_ASSERT(current_select == curr_sel);
+ DBUG_ASSERT(current_select == curr_sel ||
+ (curr_sel == NULL && current_select == &builtin_select));
if (curr_sel)
{
curr_sel->register_unit(unit, &curr_sel->context);
@@ -9391,7 +9396,8 @@ TABLE_LIST *LEX::parsed_derived_table(SELECT_LEX_UNIT *unit,
// Add the subtree of subquery to the current SELECT_LEX
SELECT_LEX *curr_sel= select_stack_head();
- DBUG_ASSERT(current_select == curr_sel);
+ DBUG_ASSERT(current_select == curr_sel ||
+ (curr_sel == NULL && current_select == &builtin_select));
Table_ident *ti= new (thd->mem_root) Table_ident(unit);
if (ti == NULL)
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 3d8505e5942..d0a18d4c578 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -3632,8 +3632,9 @@ public:
if (unlikely(!select_stack_top))
{
- current_select= NULL;
- DBUG_PRINT("info", ("Top Select is empty"));
+ current_select= &builtin_select;
+ DBUG_PRINT("info", ("Top Select is empty -> sel builtin: %p",
+ current_select));
}
else
current_select= select_stack[select_stack_top - 1];