Commit 15de3c62 authored by Ajo Robert's avatar Ajo Robert

Bug#19817021 CRASH IN TABLE_LIST::PREPARE_SECURITY WHEN

DOING BAD DDL IN PREPARED STATEMENT

Analysis
========
A repeat execution of the prepared statement 'ALTER TABLE v1
CHECK PARTITION' where v1 is a view leads to server exit.

ALTER TABLE ... CHECK PARTITION is not applicable for views
and check for the same check is missing. This leads to
further execution and creation of derived table for the view
(Allocated under temp_table mem_root). Any reference to open
 view or related pointers from second execution leads to
server exit as the same was freed at previous execution closure.

Fix:
======
Added check for view in mysql_admin_table() on PARTITION
operation. This will prevent mysql_admin_table() from
going ahead and creating temp table and related issues.
Changed message on admin table view operation error to
be more appropriate.
parent 4b4a0532
...@@ -4414,57 +4414,57 @@ test.t1 repair status OK ...@@ -4414,57 +4414,57 @@ test.t1 repair status OK
test.t2 repair status OK test.t2 repair status OK
test.t3 repair status OK test.t3 repair status OK
test.v1 repair Error 'test.v1' is not BASE TABLE test.v1 repair Error 'test.v1' is not BASE TABLE
test.v1 repair error Corrupt test.v1 repair status Operation failed
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 optimize status OK test.t1 optimize status OK
test.t2 optimize status OK test.t2 optimize status OK
test.t3 optimize status OK test.t3 optimize status OK
test.v1 optimize Error 'test.v1' is not BASE TABLE test.v1 optimize Error 'test.v1' is not BASE TABLE
test.v1 optimize error Corrupt test.v1 optimize status Operation failed
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 analyze status Table is already up to date test.t1 analyze status Table is already up to date
test.t2 analyze status Table is already up to date test.t2 analyze status Table is already up to date
test.t3 analyze status Table is already up to date test.t3 analyze status Table is already up to date
test.v1 analyze Error 'test.v1' is not BASE TABLE test.v1 analyze Error 'test.v1' is not BASE TABLE
test.v1 analyze error Corrupt test.v1 analyze status Operation failed
call bug13012()| call bug13012()|
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 repair status OK test.t1 repair status OK
test.t2 repair status OK test.t2 repair status OK
test.t3 repair status OK test.t3 repair status OK
test.v1 repair Error 'test.v1' is not BASE TABLE test.v1 repair Error 'test.v1' is not BASE TABLE
test.v1 repair error Corrupt test.v1 repair status Operation failed
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 optimize status OK test.t1 optimize status OK
test.t2 optimize status OK test.t2 optimize status OK
test.t3 optimize status OK test.t3 optimize status OK
test.v1 optimize Error 'test.v1' is not BASE TABLE test.v1 optimize Error 'test.v1' is not BASE TABLE
test.v1 optimize error Corrupt test.v1 optimize status Operation failed
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 analyze status Table is already up to date test.t1 analyze status Table is already up to date
test.t2 analyze status Table is already up to date test.t2 analyze status Table is already up to date
test.t3 analyze status Table is already up to date test.t3 analyze status Table is already up to date
test.v1 analyze Error 'test.v1' is not BASE TABLE test.v1 analyze Error 'test.v1' is not BASE TABLE
test.v1 analyze error Corrupt test.v1 analyze status Operation failed
call bug13012()| call bug13012()|
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 repair status OK test.t1 repair status OK
test.t2 repair status OK test.t2 repair status OK
test.t3 repair status OK test.t3 repair status OK
test.v1 repair Error 'test.v1' is not BASE TABLE test.v1 repair Error 'test.v1' is not BASE TABLE
test.v1 repair error Corrupt test.v1 repair status Operation failed
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 optimize status OK test.t1 optimize status OK
test.t2 optimize status OK test.t2 optimize status OK
test.t3 optimize status OK test.t3 optimize status OK
test.v1 optimize Error 'test.v1' is not BASE TABLE test.v1 optimize Error 'test.v1' is not BASE TABLE
test.v1 optimize error Corrupt test.v1 optimize status Operation failed
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 analyze status Table is already up to date test.t1 analyze status Table is already up to date
test.t2 analyze status Table is already up to date test.t2 analyze status Table is already up to date
test.t3 analyze status Table is already up to date test.t3 analyze status Table is already up to date
test.v1 analyze Error 'test.v1' is not BASE TABLE test.v1 analyze Error 'test.v1' is not BASE TABLE
test.v1 analyze error Corrupt test.v1 analyze status Operation failed
drop procedure bug13012| drop procedure bug13012|
drop view v1| drop view v1|
select * from t1 order by data| select * from t1 order by data|
......
...@@ -2402,28 +2402,28 @@ CREATE VIEW v1 AS SELECT id FROM t1; ...@@ -2402,28 +2402,28 @@ CREATE VIEW v1 AS SELECT id FROM t1;
OPTIMIZE TABLE v1; OPTIMIZE TABLE v1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.v1 optimize Error 'test.v1' is not BASE TABLE test.v1 optimize Error 'test.v1' is not BASE TABLE
test.v1 optimize error Corrupt test.v1 optimize status Operation failed
ANALYZE TABLE v1; ANALYZE TABLE v1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.v1 analyze Error 'test.v1' is not BASE TABLE test.v1 analyze Error 'test.v1' is not BASE TABLE
test.v1 analyze error Corrupt test.v1 analyze status Operation failed
REPAIR TABLE v1; REPAIR TABLE v1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.v1 repair Error 'test.v1' is not BASE TABLE test.v1 repair Error 'test.v1' is not BASE TABLE
test.v1 repair error Corrupt test.v1 repair status Operation failed
DROP TABLE t1; DROP TABLE t1;
OPTIMIZE TABLE v1; OPTIMIZE TABLE v1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.v1 optimize Error 'test.v1' is not BASE TABLE test.v1 optimize Error 'test.v1' is not BASE TABLE
test.v1 optimize error Corrupt test.v1 optimize status Operation failed
ANALYZE TABLE v1; ANALYZE TABLE v1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.v1 analyze Error 'test.v1' is not BASE TABLE test.v1 analyze Error 'test.v1' is not BASE TABLE
test.v1 analyze error Corrupt test.v1 analyze status Operation failed
REPAIR TABLE v1; REPAIR TABLE v1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.v1 repair Error 'test.v1' is not BASE TABLE test.v1 repair Error 'test.v1' is not BASE TABLE
test.v1 repair error Corrupt test.v1 repair status Operation failed
DROP VIEW v1; DROP VIEW v1;
create definer = current_user() sql security invoker view v1 as select 1; create definer = current_user() sql security invoker view v1 as select 1;
show create view v1; show create view v1;
......
/* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. /* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights
reserved.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -248,7 +249,8 @@ static inline bool table_not_corrupt_error(uint sql_errno) ...@@ -248,7 +249,8 @@ static inline bool table_not_corrupt_error(uint sql_errno)
sql_errno == ER_LOCK_WAIT_TIMEOUT || sql_errno == ER_LOCK_WAIT_TIMEOUT ||
sql_errno == ER_LOCK_DEADLOCK || sql_errno == ER_LOCK_DEADLOCK ||
sql_errno == ER_CANT_LOCK_LOG_TABLE || sql_errno == ER_CANT_LOCK_LOG_TABLE ||
sql_errno == ER_OPEN_AS_READONLY); sql_errno == ER_OPEN_AS_READONLY ||
sql_errno == ER_WRONG_OBJECT);
} }
...@@ -333,7 +335,13 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -333,7 +335,13 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
lex->query_tables_last= &table->next_global; lex->query_tables_last= &table->next_global;
lex->query_tables_own_last= 0; lex->query_tables_own_last= 0;
if (view_operator_func == NULL) /*
CHECK TABLE command is allowed for views as well. Check on alter flags
to differentiate from ALTER TABLE...CHECK PARTITION on which view is not
allowed.
*/
if (lex->alter_info.flags & ALTER_ADMIN_PARTITION ||
view_operator_func == NULL)
table->required_type=FRMTYPE_TABLE; table->required_type=FRMTYPE_TABLE;
if (!thd->locked_tables_mode && repair_table_use_frm) if (!thd->locked_tables_mode && repair_table_use_frm)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment