summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2022-05-04 17:35:59 +0300
committerMonty <monty@mariadb.org>2022-07-09 20:52:33 +0300
commit9e4640a55c74cce85c537222446700e09e582b68 (patch)
tree5b020370aabc37cc08c7fc63cf01c381f439f0ec
parentf39842c29d66f8eae085ab3539282ac7a16a7952 (diff)
downloadmariadb-git-9e4640a55c74cce85c537222446700e09e582b68.tar.gz
Fixed crashing bug in create_internal_tmp_table_from_heap()
An assert/crash could happen if newtable.alias would be reallocated, (for example if newtable.alias.safe_c_ptr() was called) when doing *table= newtable. Fixed by ensuring that we keep the original state of the alias in 'table'.
-rw-r--r--sql/sql_select.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 4cdc355bd15..ea4e94458fe 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -20827,6 +20827,7 @@ create_internal_tmp_table_from_heap(THD *thd, TABLE *table,
TABLE_SHARE share;
const char *save_proc_info;
int write_err= 0;
+ String tmp_alias;
DBUG_ENTER("create_internal_tmp_table_from_heap");
if (is_duplicate)
*is_duplicate= FALSE;
@@ -20919,9 +20920,18 @@ create_internal_tmp_table_from_heap(THD *thd, TABLE *table,
plugin_unlock(0, table->s->db_plugin);
share.db_plugin= my_plugin_lock(0, share.db_plugin);
new_table.s= table->s; // Keep old share
+
+ /*
+ The following work with alias has to be done as new_table.alias() may have
+ been reallocated and we want to keep the original one.
+ */
+ tmp_alias.move(table->alias);
*table= new_table;
+ table->alias.move(tmp_alias);
+ new_table.alias.free();
+ /* Get the new share */
*table->s= share;
-
+
table->file->change_table_ptr(table, table->s);
table->use_all_columns();
if (save_proc_info)