diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index ccdb46f10d0..1dc97124a07 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -658,4 +658,17 @@ create procedure bug9529_9012345678901234567890123456789012345678901234567890123 begin end| ERROR 42000: Identifier name 'bug9529_90123456789012345678901234567890123456789012345678901234567890' is too long +drop procedure if exists bug10969| +create procedure bug10969() +begin +declare s1 int default 0; +select default(s1) from t30; +end| +ERROR 42000: Incorrect column name 's1' +create procedure bug10969() +begin +declare s1 int default 0; +select default(t30.s1) from t30; +end| +drop procedure bug10969| drop table t1| diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index a2a43110b54..891e282e335 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -930,6 +930,29 @@ begin end| +# +# BUG#10969: Stored procedures: crash if default() function +# +--disable_warnings +drop procedure if exists bug10969| +--enable_warnings +--error ER_WRONG_COLUMN_NAME +create procedure bug10969() +begin + declare s1 int default 0; + select default(s1) from t30; +end| + +# This should work +create procedure bug10969() +begin + declare s1 int default 0; + select default(t30.s1) from t30; +end| + +drop procedure bug10969| + + # # BUG#NNNN: New bug synopsis # diff --git a/sql/item.h b/sql/item.h index 18b419dd6d5..f2e8e582780 100644 --- a/sql/item.h +++ b/sql/item.h @@ -584,6 +584,13 @@ public: Item::maybe_null= TRUE; } + /* For error printing */ + inline void my_name(char **strp, uint *lengthp) + { + *strp= m_name.str; + *lengthp= m_name.length; + } + bool is_splocal() { return 1; } /* Needed for error checking */ Item *this_item(); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 708dcb7a0d9..861216ebc96 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -4343,7 +4343,18 @@ simple_expr: | CONVERT_SYM '(' expr USING charset_name ')' { $$= new Item_func_conv_charset($3,$5); } | DEFAULT '(' simple_ident ')' - { $$= new Item_default_value($3); } + { + if ($3->is_splocal()) + { + LEX_STRING name; + Item_splocal *il= static_cast($3); + + il->my_name(&name.str, &name.length); + my_error(ER_WRONG_COLUMN_NAME, MYF(0), name.str); + YYABORT; + } + $$= new Item_default_value($3); + } | VALUES '(' simple_ident ')' { $$= new Item_insert_value($3); } | FUNC_ARG0 '(' ')'