diff --git a/mysql-test/r/default.result b/mysql-test/r/default.result index 014d4bee6c8..39202f5eabb 100644 --- a/mysql-test/r/default.result +++ b/mysql-test/r/default.result @@ -3362,4 +3362,6 @@ a b t 4 5 4 also expression DEFAULT(0)+0 4 5 5 the value of the DEFAULT(a), that is b drop table t1; +create table t1 (col1 int default(-(default(col1)))); +ERROR 01000: Expression for field `col1` is refering to uninitialized field `col1` # end of 10.2 test diff --git a/mysql-test/t/default.test b/mysql-test/t/default.test index c96f8ac239b..b9f97b08a72 100644 --- a/mysql-test/t/default.test +++ b/mysql-test/t/default.test @@ -2069,4 +2069,10 @@ insert into t1 values (b, 5, '5 the value of the DEFAULT(a), that is b'); select * from t1 order by t; drop table t1; +# +# MDEV-10352 Server crashes in Field::set_default on CREATE TABLE +# +--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD +create table t1 (col1 int default(-(default(col1)))); + --echo # end of 10.2 test diff --git a/sql/item.cc b/sql/item.cc index 3b3e878f4d3..c34d27fa63b 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -8853,9 +8853,11 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions) table_map Item_default_value::used_tables() const { - if (field && field->default_value && field->default_value->flags) - return field->default_value->expr->used_tables(); - return static_cast(0); + if (!field || !field->default_value) + return static_cast(0); + if (!field->default_value->expr) // not fully parsed field + return static_cast(RAND_TABLE_BIT); + return field->default_value->expr->used_tables(); } /**