diff options
author | Evgeny Potemkin <epotemkin@mysql.com> | 2008-11-05 18:40:23 +0300 |
---|---|---|
committer | Evgeny Potemkin <epotemkin@mysql.com> | 2008-11-05 18:40:23 +0300 |
commit | 3c49cb0795fae5c43d00a499b1d4f71365bb9ba9 (patch) | |
tree | a52cac0068f7fecdc739e890dc0bc688ece7ae3c /sql/item_cmpfunc.cc | |
parent | c8ee385d89338cca73dd069c7c03074d171cc8f4 (diff) | |
download | mariadb-git-3c49cb0795fae5c43d00a499b1d4f71365bb9ba9.tar.gz |
Bug#37870: Usage of uninitialized value caused failed assertion.
The convert_constant_item function converts a constant to integer using
field for condition like 'field = a_constant'. In some cases the
convert_constant_item is called for a subquery when outer select is already
being executed, so convert_constant_item saves field's value to prevent its
corruption. For EXPLAIN and at the prepare phase field's value isn't
initialized yet, thus when convert_constant_item tries to restore saved
value it fails assertion.
Now the convert_constant_item doesn't save/restore field's value if it's
haven't been read yet. Outer constant values are always saved.
mysql-test/r/explain.result:
Added a test case for the bug#37870.
mysql-test/t/explain.test:
Added a test case for the bug#37870.
sql/item_cmpfunc.cc:
Bug#37870: Usage of uninitialized value caused failed assertion.
Now the convert_constant_item doesn't save/restore field's value if it's
haven't been read yet. Outer constant values are always saved.
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r-- | sql/item_cmpfunc.cc | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index cefa479fea6..3fd925c1182 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -413,11 +413,15 @@ static bool convert_constant_item(THD *thd, Item_field *field_item, thd->count_cuted_fields= CHECK_FIELD_IGNORE; /* - Store the value of the field/constant if it references an outer field because - the call to save_in_field below overrides that value. - Don't save value of the field for EXPLAIN since it's not initialized. + Store the value of the field/constant if it references an outer field + because the call to save_in_field below overrides that value. + Don't save field value if no data has been read yet. + Outer constant values are always saved. */ - if (field_item->depended_from && (!thd->lex->describe || field_item->const_item())) + bool save_field_value= (field_item->depended_from && + (field_item->const_item() || + !(field->table->status & STATUS_NO_RECORD))); + if (save_field_value) orig_field_val= field->val_int(); if (!(*item)->is_null() && !(*item)->save_in_field(field, 1)) { @@ -428,7 +432,7 @@ static bool convert_constant_item(THD *thd, Item_field *field_item, result= 1; // Item was replaced } /* Restore the original field value. */ - if (field_item->depended_from && (!thd->lex->describe || field_item->const_item())) + if (save_field_value) { result= field->store(orig_field_val, TRUE); /* orig_field_val must be a valid value that can be restored back. */ |