Skip to content

Commit

Permalink
MDEV-26637: (variables) ASAN: main.metadata and user_variables.basic …
Browse files Browse the repository at this point in the history
…MTR failures after MDEV-26572

Prohibit user variables without name
  • Loading branch information
sanja-byelkin committed Oct 12, 2021
1 parent af8b2c6 commit 8f7edb7
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 31 deletions.
11 changes: 1 addition & 10 deletions mysql-test/main/func_in.result
Expand Up @@ -784,7 +784,7 @@ SELECT 1 IN (YEAR(FROM_UNIXTIME(NULL)) ,1);
# Bug#13012483: EXPLAIN EXTENDED, PREPARED STATEMENT, CRASH IN CHECK_SIMPLE_EQUALITY
#
CREATE TABLE t1 (a INT);
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @a:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
EXECUTE s;
1
DROP TABLE t1;
Expand All @@ -805,15 +805,6 @@ select * from t1 where IF(1,a,a)='2.1';
a b
drop table t1;
#
# LP bug#992380 Crash when creating PS for a query with
# subquery in WHERE (see also mysql bug#13012483)
#
CREATE TABLE t1 (a INT);
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
EXECUTE s;
1
DROP TABLE t1;
#
# End of 5.3 tests
#
create table t1 (a int);
Expand Down
11 changes: 1 addition & 10 deletions mysql-test/main/func_in.test
Expand Up @@ -567,7 +567,7 @@ SELECT 1 IN (YEAR(FROM_UNIXTIME(NULL)) ,1);
--echo #

CREATE TABLE t1 (a INT);
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @a:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
EXECUTE s;

DROP TABLE t1;
Expand Down Expand Up @@ -595,15 +595,6 @@ select * from t1 where a='2.1';
select * from t1 where b='2.1';
select * from t1 where IF(1,a,a)='2.1';
drop table t1;
--echo #
--echo # LP bug#992380 Crash when creating PS for a query with
--echo # subquery in WHERE (see also mysql bug#13012483)
--echo #
CREATE TABLE t1 (a INT);
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
EXECUTE s;

DROP TABLE t1;

--echo #
--echo # End of 5.3 tests
Expand Down
12 changes: 6 additions & 6 deletions mysql-test/main/metadata.result
Expand Up @@ -553,19 +553,19 @@ d0l d09 d10
# MDEV-12862 Data type of @a:=1e0 depends on the session character set
#
SET NAMES utf8;
CREATE TABLE t1 AS SELECT @:=1e0;
CREATE TABLE t1 AS SELECT @a:=1e0;
SELECT * FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 @:=1e0 @:=1e0 5 3 1 N 36865 31 63
@:=1e0
def test t1 t1 @a:=1e0 @a:=1e0 5 3 1 N 36865 31 63
@a:=1e0
1
DROP TABLE t1;
SET NAMES latin1;
CREATE TABLE t1 AS SELECT @:=1e0;
CREATE TABLE t1 AS SELECT @a:=1e0;
SELECT * FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 @:=1e0 @:=1e0 5 3 1 N 36865 31 63
@:=1e0
def test t1 t1 @a:=1e0 @a:=1e0 5 3 1 N 36865 31 63
@a:=1e0
1
DROP TABLE t1;
#
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/main/metadata.test
Expand Up @@ -345,11 +345,11 @@ SELECT
--echo #
--enable_metadata
SET NAMES utf8;
CREATE TABLE t1 AS SELECT @:=1e0;
CREATE TABLE t1 AS SELECT @a:=1e0;
SELECT * FROM t1;
DROP TABLE t1;
SET NAMES latin1;
CREATE TABLE t1 AS SELECT @:=1e0;
CREATE TABLE t1 AS SELECT @a:=1e0;
SELECT * FROM t1;
DROP TABLE t1;
--disable_metadata
Expand Down
5 changes: 2 additions & 3 deletions plugin/user_variables/mysql-test/user_variables/basic.result
Expand Up @@ -29,13 +29,13 @@ SET @dec_var=CAST(1 AS DECIMAL(20, 10));
SET @time_var=CAST('2016-02-25' AS DATE);
SET @' @#^%'='Value of variable with odd name';
SET @''='Value of variable with empty name';
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '='Value of variable with empty name'' at line 1
SET @null_var=NULL;
SELECT COUNT(*) FROM INFORMATION_SCHEMA.USER_VARIABLES;
COUNT(*)
10
9
SELECT * FROM INFORMATION_SCHEMA.USER_VARIABLES ORDER BY VARIABLE_NAME;
VARIABLE_NAME VARIABLE_VALUE VARIABLE_TYPE CHARACTER_SET_NAME
Value of variable with empty name VARCHAR latin1
@#^% Value of variable with odd name VARCHAR latin1
dec_var 1.0000000000 DECIMAL latin1
double_var 1 DOUBLE latin1
Expand All @@ -47,7 +47,6 @@ uint_var 2 INT UNSIGNED latin1
utf8str_var UTF8 string value VARCHAR utf8mb3
SHOW USER_VARIABLES;
Variable_name Value
Value of variable with empty name
@#^% Value of variable with odd name
dec_var 1.0000000000
double_var 1
Expand Down
1 change: 1 addition & 0 deletions plugin/user_variables/mysql-test/user_variables/basic.test
Expand Up @@ -12,6 +12,7 @@ SET @double_var=CAST(1 AS DOUBLE);
SET @dec_var=CAST(1 AS DECIMAL(20, 10));
SET @time_var=CAST('2016-02-25' AS DATE);
SET @' @#^%'='Value of variable with odd name';
--error ER_PARSE_ERROR
SET @''='Value of variable with empty name';
SET @null_var=NULL;

Expand Down
33 changes: 33 additions & 0 deletions sql/sql_yacc.yy
Expand Up @@ -3555,6 +3555,11 @@ simple_target_specification:
}
| '@' ident_or_text
{
if (!$2.length)
{
thd->parse_error();
YYABORT;
}
$$= new (thd->mem_root) Item_func_get_user_var(thd, &$2);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
Expand Down Expand Up @@ -10934,6 +10939,11 @@ variable_aux:
ident_or_text SET_VAR expr
{
Item_func_set_user_var *item;
if (!$1.length)
{
thd->parse_error();
YYABORT;
}
$$= item= new (thd->mem_root) Item_func_set_user_var(thd, &$1, $3);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
Expand All @@ -10943,6 +10953,11 @@ variable_aux:
}
| ident_or_text
{
if (!$1.length)
{
thd->parse_error();
YYABORT;
}
$$= new (thd->mem_root) Item_func_get_user_var(thd, &$1);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
Expand Down Expand Up @@ -12584,6 +12599,12 @@ select_var_ident: select_outvar
select_outvar:
'@' ident_or_text
{
if (!$2.length)
{
thd->parse_error();
YYABORT;
}

$$ = Lex->result ? new (thd->mem_root) my_var_user(&$2) : NULL;
}
| ident_or_text
Expand Down Expand Up @@ -14564,6 +14585,12 @@ field_or_var:
simple_ident_nospvar {$$= $1;}
| '@' ident_or_text
{
if (!$2.length)
{
thd->parse_error();
YYABORT;
}

$$= new (thd->mem_root) Item_user_var_as_out_param(thd, &$2);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
Expand Down Expand Up @@ -16379,6 +16406,12 @@ option_value_no_option_type:
}
| '@' ident_or_text equal
{
if (!$2.length)
{
thd->parse_error();
YYABORT;
}

if (sp_create_assignment_lex(thd, $1.str))
MYSQL_YYABORT;
}
Expand Down

0 comments on commit 8f7edb7

Please sign in to comment.