diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-04-22 14:01:58 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-04-22 14:01:58 +0400 |
commit | 279b50b4eb69f882510f069e79715c38dc13355e (patch) | |
tree | 115d0e09a5906c1673781fe7a3eba8556846ce6a /sql | |
parent | f4b27400185bab217da11f8781eebb09a8502304 (diff) | |
download | mariadb-git-279b50b4eb69f882510f069e79715c38dc13355e.tar.gz |
MDEV-14041 Server crashes in String::length on queries with functions and ROLLUP
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item.h | 39 | ||||
-rw-r--r-- | sql/item_func.h | 11 |
2 files changed, 46 insertions, 4 deletions
diff --git a/sql/item.h b/sql/item.h index 4b93d3f9164..5c432887ed9 100644 --- a/sql/item.h +++ b/sql/item.h @@ -663,6 +663,45 @@ protected: SEL_TREE *get_mm_tree_for_const(RANGE_OPT_PARAM *param); Field *create_tmp_field(bool group, TABLE *table, uint convert_int_length); + /* Helper methods, to get an Item value from another Item */ + double val_real_from_item(Item *item) + { + DBUG_ASSERT(fixed == 1); + double value= item->val_real(); + null_value= item->null_value; + return value; + } + longlong val_int_from_item(Item *item) + { + DBUG_ASSERT(fixed == 1); + longlong value= item->val_int(); + null_value= item->null_value; + return value; + } + String *val_str_from_item(Item *item, String *str) + { + DBUG_ASSERT(fixed == 1); + String *res= item->val_str(str); + if (res) + res->set_charset(collation.collation); + if ((null_value= item->null_value)) + res= NULL; + return res; + } + my_decimal *val_decimal_from_item(Item *item, my_decimal *decimal_value) + { + DBUG_ASSERT(fixed == 1); + my_decimal *value= item->val_decimal(decimal_value); + if ((null_value= item->null_value)) + value= NULL; + return value; + } + bool get_date_from_item(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate) + { + bool rc= item->get_date(ltime, fuzzydate); + null_value= MY_TEST(rc || item->null_value); + return rc; + } /* This method is used if the item was not null but convertion to TIME/DATE/DATETIME failed. We return a zero date if allowed, diff --git a/sql/item_func.h b/sql/item_func.h index 9700429d543..36a2f94b31d 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1120,10 +1120,13 @@ public: name= a->name; name_length= a->name_length; } - double val_real() { return args[0]->val_real(); } - longlong val_int() { return args[0]->val_int(); } - String *val_str(String *str) { return args[0]->val_str(str); } - my_decimal *val_decimal(my_decimal *dec) { return args[0]->val_decimal(dec); } + double val_real() { return val_real_from_item(args[0]); } + longlong val_int() { return val_int_from_item(args[0]); } + String *val_str(String *str) { return val_str_from_item(args[0], str); } + my_decimal *val_decimal(my_decimal *dec) + { return val_decimal_from_item(args[0], dec); } + bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + { return get_date_from_item(args[0], ltime, fuzzydate); } const char *func_name() const { return "rollup_const"; } bool const_item() const { return 0; } Item_result result_type() const { return args[0]->result_type(); } |