mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
5.1 version of fix for:
Bug #23667 "CREATE TABLE LIKE is not isolated from alteration by other connections" Bug #18950 "CREATE TABLE LIKE does not obtain LOCK_open" As well as: Bug #25578 "CREATE TABLE LIKE does not require any privileges on source table". The first and the second bugs resulted in various errors and wrong binary log order when one tried to execute concurrently CREATE TABLE LIKE statement and DDL statements on source table or DML/DDL statements on its target table. The problem was caused by incomplete protection/table-locking against concurrent statements implemented in mysql_create_like_table() routine. We solve it by simply implementing such protection in proper way. Most of actual work for 5.1 was already done by fix for bug 20662 and preliminary patch changing locking in ALTER TABLE. The third bug allowed user who didn't have any privileges on table create its copy and therefore circumvent privilege check for SHOW CREATE TABLE. This patch solves this problem by adding privilege check, which was missing. Finally it also removes some duplicated code from mysql_create_like_table() and thus fixes bug #26869 "TABLE_LIST::table_name_length inconsistent with TABLE_LIST::table_name".
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
"FUNCTION" : "PROCEDURE")
|
||||
|
||||
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
|
||||
static bool check_show_create_table_access(THD *thd, TABLE_LIST *table);
|
||||
|
||||
const char *any_db="*any*"; // Special symbol for check_access
|
||||
|
||||
@@ -2240,9 +2241,9 @@ mysql_execute_command(THD *thd)
|
||||
if (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE)
|
||||
thd->options|= OPTION_KEEP_LOG;
|
||||
/* regular create */
|
||||
if (lex->like_name)
|
||||
res= mysql_create_like_table(thd, create_table, &lex->create_info,
|
||||
lex->like_name);
|
||||
if (lex->create_info.options & HA_LEX_CREATE_TABLE_LIKE)
|
||||
res= mysql_create_like_table(thd, create_table, select_tables,
|
||||
&lex->create_info);
|
||||
else
|
||||
{
|
||||
res= mysql_create_table(thd, create_table->db,
|
||||
@@ -2432,12 +2433,7 @@ end_with_restore_list:
|
||||
/* Ignore temporary tables if this is "SHOW CREATE VIEW" */
|
||||
if (lex->only_view)
|
||||
first_table->skip_temporary= 1;
|
||||
|
||||
if (check_access(thd, SELECT_ACL | EXTRA_ACL, first_table->db,
|
||||
&first_table->grant.privilege, 0, 0,
|
||||
test(first_table->schema_table)))
|
||||
goto error;
|
||||
if (grant_option && check_grant(thd, SELECT_ACL, all_tables, 2, UINT_MAX, 0))
|
||||
if (check_show_create_table_access(thd, first_table))
|
||||
goto error;
|
||||
res= mysqld_show_create(thd, first_table);
|
||||
break;
|
||||
@@ -6854,6 +6850,25 @@ bool insert_precheck(THD *thd, TABLE_LIST *tables)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@brief Check privileges for SHOW CREATE TABLE statement.
|
||||
|
||||
@param thd Thread context
|
||||
@param table Target table
|
||||
|
||||
@retval TRUE Failure
|
||||
@retval FALSE Success
|
||||
*/
|
||||
|
||||
static bool check_show_create_table_access(THD *thd, TABLE_LIST *table)
|
||||
{
|
||||
return check_access(thd, SELECT_ACL | EXTRA_ACL, table->db,
|
||||
&table->grant.privilege, 0, 0,
|
||||
test(table->schema_table)) ||
|
||||
grant_option && check_grant(thd, SELECT_ACL, table, 2, UINT_MAX, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
CREATE TABLE query pre-check
|
||||
|
||||
@@ -6919,6 +6934,11 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables,
|
||||
if (tables && check_table_access(thd, SELECT_ACL, tables,0))
|
||||
goto err;
|
||||
}
|
||||
else if (lex->create_info.options & HA_LEX_CREATE_TABLE_LIKE)
|
||||
{
|
||||
if (check_show_create_table_access(thd, tables))
|
||||
goto err;
|
||||
}
|
||||
error= FALSE;
|
||||
|
||||
err:
|
||||
|
||||
Reference in New Issue
Block a user