diff options
author | anozdrin/alik@quad. <> | 2008-02-20 22:23:39 +0300 |
---|---|---|
committer | anozdrin/alik@quad. <> | 2008-02-20 22:23:39 +0300 |
commit | 576794214f20f9dbbf20ff1bd9c63c7ae82a9e22 (patch) | |
tree | 2a2ddbf915e37d20e3a5b3c2624dad304ae6431f /sql/sql_view.cc | |
parent | 812ee08488c5534e09a1bb828f2b857b073fb86f (diff) | |
download | mariadb-git-576794214f20f9dbbf20ff1bd9c63c7ae82a9e22.tar.gz |
Fix for Bug#34337: Server crash when Altering a view using
a table name.
The problem was that fill_defined_view_parts() did not return
an error if a table is going to be altered. That happened if
the table was already in the table cache. In that case,
open_table() returned non-NULL value (valid TABLE-instance from
the cache).
The fix is to ensure that an error is thrown even if the table
is in the cache.
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r-- | sql/sql_view.cc | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 0b0763afb84..0642a2d2e17 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -182,10 +182,33 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view) TABLE_LIST decoy; memcpy (&decoy, view, sizeof (TABLE_LIST)); - if (!open_table(thd, &decoy, thd->mem_root, ¬_used, OPEN_VIEW_NO_PARSE) && - !decoy.view) + + /* + Let's reset decoy.view before calling open_table(): when we start + supporting ALTER VIEW in PS/SP that may save us from a crash. + */ + + decoy.view= NULL; + + /* + open_table() will return NULL if 'decoy' is idenitifying a view *and* + there is no TABLE object for that view in the table cache. However, + decoy.view will be set to 1. + + If there is a TABLE-instance for the oject identified by 'decoy', + open_table() will return that instance no matter if it is a table or + a view. + + Thus, there is no need to check for the return value of open_table(), + since the return value itself does not mean anything. + */ + + open_table(thd, &decoy, thd->mem_root, ¬_used, OPEN_VIEW_NO_PARSE); + + if (!decoy.view) { - /* It's a table */ + /* It's a table. */ + my_error(ER_WRONG_OBJECT, MYF(0), view->db, view->table_name, "VIEW"); return TRUE; } |