summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Lindström <jan.lindstrom@mariadb.com>2021-06-29 15:18:28 +0300
committerJan Lindström <jan.lindstrom@mariadb.com>2021-06-29 15:18:28 +0300
commit3573429c87956f1f51162ba08280ab009d204412 (patch)
treefbdb0b8f526a50a7815cc8dc57d32b1af2c6245c
parentc29f45ce77c0eb89e5169c5c2b0f05e2a6198132 (diff)
downloadmariadb-git-bb-10.6-MDEV-25906.tar.gz
MDEV-25906 : SIGSEGV in flush_tables_with_read_lock on FTWRL or FTFE | SIGSEGV in ha_maria::extrabb-10.6-MDEV-25906
Problem was that flush_tables_with_read_lock did not check is base table database information_schema or performance_schema where FLUSH is not supported. Furthermore, it did not check is there even any base table.
-rw-r--r--mysql-test/main/flush.result25
-rw-r--r--mysql-test/main/flush.test31
-rw-r--r--sql/sql_reload.cc48
3 files changed, 88 insertions, 16 deletions
diff --git a/mysql-test/main/flush.result b/mysql-test/main/flush.result
index 941dc63e3da..0630a424e1c 100644
--- a/mysql-test/main/flush.result
+++ b/mysql-test/main/flush.result
@@ -615,3 +615,28 @@ show status like "Threads_cached";
Variable_name Value
Threads_cached 0
set @@global.thread_cache_size=@save_thread_cache_size;
+#
+# MDEV-25906: SIGSEGV in flush_tables_with_read_lock on FTWRL or FTFE | SIGSEGV in ha_maria::extra
+#
+CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d;
+CREATE VIEW v2 AS SELECT * FROM v;
+FLUSH TABLE v WITH READ LOCK;
+ERROR HY000: 'test.v' is not of type 'BASE TABLE'
+FLUSH TABLE v FOR EXPORT;
+ERROR HY000: 'test.v' is not of type 'BASE TABLE'
+FLUSH TABLE v2 WITH READ LOCK;
+ERROR HY000: 'test.v2' is not of type 'BASE TABLE'
+DROP VIEW v2;
+DROP VIEW v;
+CREATE VIEW v(c) AS SELECT column_name FROM information_schema.columns;
+FLUSH TABLE v WITH READ LOCK;
+ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
+FLUSH TABLE v FOR EXPORT;
+ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
+DROP VIEW v;
+CREATE VIEW v(u) AS SELECT user FROM performance_schema.accounts;
+FLUSH TABLE v WITH READ LOCK;
+ERROR 42000: Access denied for user 'root'@'localhost' to database 'performance_schema'
+FLUSH TABLE v FOR EXPORT;
+ERROR 42000: Access denied for user 'root'@'localhost' to database 'performance_schema'
+DROP VIEW v;
diff --git a/mysql-test/main/flush.test b/mysql-test/main/flush.test
index 97830238b0e..dd488070ce8 100644
--- a/mysql-test/main/flush.test
+++ b/mysql-test/main/flush.test
@@ -1,3 +1,5 @@
+--source include/have_perfschema.inc
+
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
connection con1;
@@ -732,3 +734,32 @@ set @@global.thread_cache_size=0;
flush threads;
show status like "Threads_cached";
set @@global.thread_cache_size=@save_thread_cache_size;
+
+--echo #
+--echo # MDEV-25906: SIGSEGV in flush_tables_with_read_lock on FTWRL or FTFE | SIGSEGV in ha_maria::extra
+--echo #
+
+CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d;
+CREATE VIEW v2 AS SELECT * FROM v;
+--error ER_WRONG_OBJECT
+FLUSH TABLE v WITH READ LOCK;
+--error ER_WRONG_OBJECT
+FLUSH TABLE v FOR EXPORT;
+--error ER_WRONG_OBJECT
+FLUSH TABLE v2 WITH READ LOCK;
+DROP VIEW v2;
+DROP VIEW v;
+
+CREATE VIEW v(c) AS SELECT column_name FROM information_schema.columns;
+--error ER_DBACCESS_DENIED_ERROR
+FLUSH TABLE v WITH READ LOCK;
+--error ER_DBACCESS_DENIED_ERROR
+FLUSH TABLE v FOR EXPORT;
+DROP VIEW v;
+
+CREATE VIEW v(u) AS SELECT user FROM performance_schema.accounts;
+--error ER_DBACCESS_DENIED_ERROR
+FLUSH TABLE v WITH READ LOCK;
+--error ER_DBACCESS_DENIED_ERROR
+FLUSH TABLE v FOR EXPORT;
+DROP VIEW v;
diff --git a/sql/sql_reload.cc b/sql/sql_reload.cc
index 0fa2fa10df8..91695f37906 100644
--- a/sql/sql_reload.cc
+++ b/sql/sql_reload.cc
@@ -586,29 +586,45 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables)
&lock_tables_prelocking_strategy))
goto error_reset_bits;
- if (thd->lex->type & REFRESH_FOR_EXPORT)
+ // Iterate all tables
+ for (auto table_list= all_tables; table_list;
+ table_list= table_list->next_global)
{
- // Check if all storage engines support FOR EXPORT.
- for (TABLE_LIST *table_list= all_tables; table_list;
- table_list= table_list->next_global)
+ // FLUSH [WITH READ LOCK|FOR EXPORT] not supported
+ // for information_schema or performance_schema tables
+ if (is_infoschema_db(&table_list->db) ||
+ is_perfschema_db(&table_list->db))
+ {
+ my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
+ thd->security_ctx->priv_user,
+ thd->security_ctx->priv_host,
+ table_list->db.str);
+ goto error_reset_bits;
+ }
+ // FLUSH [WITH READ LOCK|FOR EXPORT] not supported
+ // if there is no base table
+ if (!table_list->is_view() && !table_list->table)
{
- if (!(table_list->is_view() ||
- table_list->table->file->ha_table_flags() & HA_CAN_EXPORT))
+ TABLE_LIST *view= table_list->top_table();
+
+ my_error(ER_WRONG_OBJECT, MYF(0),
+ view ? view->db.str : all_tables->db.str,
+ view ? view->table_name.str : all_tables->table_name.str,
+ "BASE TABLE");
+ goto error_reset_bits;
+ }
+ if (!table_list->is_view())
+ {
+ // Check if storage engine support FOR EXPORT.
+ if ((thd->lex->type & REFRESH_FOR_EXPORT) &&
+ !(table_list->table->file->ha_table_flags() & HA_CAN_EXPORT))
{
my_error(ER_ILLEGAL_HA, MYF(0),table_list->table->file->table_type(),
table_list->db.str, table_list->table_name.str);
goto error_reset_bits;
}
- }
- }
-
- if (thd->lex->type & REFRESH_READ_LOCK)
- {
- for (auto table_list= all_tables; table_list;
- table_list= table_list->next_global)
- {
- if (!table_list->is_view() &&
- table_list->table->file->extra(HA_EXTRA_FLUSH))
+ else if ((thd->lex->type & REFRESH_READ_LOCK) &&
+ table_list->table->file->extra(HA_EXTRA_FLUSH))
goto error_reset_bits;
}
}