From 397da9d9b7cd686bb86bd36956e7da3863b21379 Mon Sep 17 00:00:00 2001 From: "mhansson/martin@linux-st28.site" <> Date: Fri, 28 Sep 2007 18:05:23 +0200 Subject: [PATCH] Bug #30832: Assertion + crash with select name_const('test', now()); The NAME_CONST function is required to work correctly with constants only. When executed with functions that return types other than those returned by Item::field_type (string, int, decimal, or real), the result gets cast to one of those types. This cannot happen for constants. Fixed by only allowing constants as arguments to NAME_CONST. --- mysql-test/r/func_misc.result | 16 ++++++++++++++++ mysql-test/t/func_misc.test | 14 ++++++++++++++ sql/item.h | 2 ++ 3 files changed, 32 insertions(+) diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result index 35101e26ff6..bb6f4127a2a 100644 --- a/mysql-test/r/func_misc.result +++ b/mysql-test/r/func_misc.result @@ -185,4 +185,20 @@ ERROR 21000: Operand should contain 1 column(s) drop table table_26093; drop function func_26093_a; drop function func_26093_b; +SELECT NAME_CONST('test', NOW()); +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('test', UPPER('test')); +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('test', NULL); +test +NULL +SELECT NAME_CONST('test', 1); +test +1 +SELECT NAME_CONST('test', 1.0); +test +1.0 +SELECT NAME_CONST('test', 'test'); +test +test End of 5.0 tests diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index 8ff62f68e45..c93e411e691 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -189,4 +189,18 @@ drop table table_26093; drop function func_26093_a; drop function func_26093_b; +# +# Bug #30832: Assertion + crash with select name_const('test',now()); +# +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('test', NOW()); +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('test', UPPER('test')); + +SELECT NAME_CONST('test', NULL); +SELECT NAME_CONST('test', 1); +SELECT NAME_CONST('test', 1.0); +SELECT NAME_CONST('test', 'test'); + --echo End of 5.0 tests + diff --git a/sql/item.h b/sql/item.h index 3c699c0eda3..cd0be343a62 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1112,6 +1112,8 @@ public: Item_name_const(Item *name_arg, Item *val): value_item(val), name_item(name_arg) { + if(!value_item->basic_const_item()) + my_error(ER_WRONG_ARGUMENTS, MYF(0), "NAME_CONST"); Item::maybe_null= TRUE; }