mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Bug#47627 SET @@{global.session}.local_variable in stored routine causes crash
This patch borrows ideas, text and code from Kristofer Pettersson's patch. An assignment of a system variable sharing the same base name as a declared stored procedure variable in the same context could lead to a crash. The reason was that during the parsing of the syntactic rule 'option_value' an uninitialized set_var object was pushed to the parameter stack of the SET statement. The parent rule 'option_type_value' interpreted the existence of variables on the parameter stack as an assignment and wrapped it in a sp_instr_set object. As the procedure later was executed an attempt was made to run the method 'check()' on an uninitialized member object (NULL value) belonging to the previously created but uninitialized object. This patch refactors the 'internal_variable_name' rule and copies the semantic analysis part to the depending parent rule: 'option_value'. This makes it possible to account for any prefixes affecting the interpretation of the internal_variable_name. mysql-test/r/sp.result: Add test case result. mysql-test/t/sp.test: Add test case for bug. sql/sql_yacc.yy: - Reduce churn in rule sys_option_value by moving to specialized functions. - Comment the the lookup in the rule internel_variable_name is a best effort operation. - Lookup for a system variable in the option_value if one was not found (the variable could have been shadowed)
This commit is contained in:
@ -6979,6 +6979,64 @@ CALL p1;
|
||||
ERROR 42S22: Unknown column 'A.b' in 'IN/ALL/ANY subquery'
|
||||
DROP PROCEDURE p1;
|
||||
DROP TABLE t1, t2;
|
||||
#
|
||||
# Bug#47627: SET @@{global.session}.local_variable in stored routine causes crash
|
||||
# Bug#48626: Crash or lost connection using SET for declared variables with @@
|
||||
#
|
||||
DROP PROCEDURE IF EXISTS p1;
|
||||
DROP PROCEDURE IF EXISTS p2;
|
||||
DROP PROCEDURE IF EXISTS p3;
|
||||
CREATE PROCEDURE p1()
|
||||
BEGIN
|
||||
DECLARE v INT DEFAULT 0;
|
||||
SET @@SESSION.v= 10;
|
||||
END//
|
||||
ERROR HY000: Unknown system variable 'v'
|
||||
CREATE PROCEDURE p2()
|
||||
BEGIN
|
||||
DECLARE v INT DEFAULT 0;
|
||||
SET v= 10;
|
||||
END//
|
||||
call p2()//
|
||||
CREATE PROCEDURE p3()
|
||||
BEGIN
|
||||
DECLARE v INT DEFAULT 0;
|
||||
SELECT @@SESSION.v;
|
||||
END//
|
||||
ERROR HY000: Unknown system variable 'v'
|
||||
CREATE PROCEDURE p4()
|
||||
BEGIN
|
||||
DECLARE v INT DEFAULT 0;
|
||||
SET @@GLOBAL.v= 10;
|
||||
END//
|
||||
ERROR HY000: Unknown system variable 'v'
|
||||
CREATE PROCEDURE p5()
|
||||
BEGIN
|
||||
DECLARE init_connect INT DEFAULT 0;
|
||||
SET init_connect= 10;
|
||||
SET @@GLOBAL.init_connect= 'SELECT 1';
|
||||
SET @@SESSION.IDENTITY= 1;
|
||||
SELECT @@SESSION.IDENTITY;
|
||||
SELECT @@GLOBAL.init_connect;
|
||||
SELECT init_connect;
|
||||
END//
|
||||
CREATE PROCEDURE p6()
|
||||
BEGIN
|
||||
DECLARE v INT DEFAULT 0;
|
||||
SET @@v= 0;
|
||||
END//
|
||||
ERROR HY000: Unknown system variable 'v'
|
||||
SET @old_init_connect= @@GLOBAL.init_connect;
|
||||
CALL p5();
|
||||
@@SESSION.IDENTITY
|
||||
1
|
||||
@@GLOBAL.init_connect
|
||||
SELECT 1
|
||||
init_connect
|
||||
10
|
||||
SET @@GLOBAL.init_connect= @old_init_connect;
|
||||
DROP PROCEDURE p2;
|
||||
DROP PROCEDURE p5;
|
||||
# ------------------------------------------------------------------
|
||||
# -- End of 5.1 tests
|
||||
# ------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user