diff options
author | Michael Widenius <monty@mariadb.org> | 2018-09-16 11:22:32 +0300 |
---|---|---|
committer | Michael Widenius <monty@mariadb.org> | 2018-09-16 11:23:27 +0300 |
commit | bd7c31621ff8f490866a5a5dfb1d99de35d062a4 (patch) | |
tree | 1763b8529de813625202134063e37591aed7a0f0 /sql | |
parent | 4dc20ff687d50b2a5d889653c11674fb1d310cf8 (diff) | |
download | mariadb-git-bd7c31621ff8f490866a5a5dfb1d99de35d062a4.tar.gz |
MDEV-17065 Crash on SHOW CREATE TABLE with CHECK CONSTRAINT
The problem was that the original alias was replaced with a new allocated
string, but constraint item's are still pointing to the original alias.
Fixed by storing the original alias used when printing constraint in the
tables mem_root.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/table.cc | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/sql/table.cc b/sql/table.cc index 585cb13a86c..f557799e7dd 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -3007,6 +3007,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, { enum open_frm_error error; uint records, i, bitmap_size, bitmap_count; + size_t tmp_length; + const char *tmp_alias; bool error_reported= FALSE; uchar *record, *bitmaps; Field **field_ptr; @@ -3033,8 +3035,15 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, } init_sql_alloc(&outparam->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); - if (outparam->alias.copy(alias, strlen(alias), table_alias_charset)) + /* + We have to store the original alias in mem_root as constraints and virtual + functions may store pointers to it + */ + tmp_length= strlen(alias); + if (!(tmp_alias= strmake_root(&outparam->mem_root, alias, tmp_length))) goto err; + + outparam->alias.set(tmp_alias, tmp_length, table_alias_charset); outparam->quick_keys.init(); outparam->covering_keys.init(); outparam->intersect_keys.init(); @@ -4487,7 +4496,7 @@ void TABLE::init(THD *thd, TABLE_LIST *tl) s->table_name.str, tl->alias); /* Fix alias if table name changes. */ - if (strcmp(alias.c_ptr(), tl->alias)) + if (!alias.alloced_length() || strcmp(alias.c_ptr(), tl->alias)) alias.copy(tl->alias, strlen(tl->alias), alias.charset()); tablenr= thd->current_tablenr++; |