#At file:///home/kgeorge/mysql/work/B46019-5.0-bugteam/ based on revid:joro@stripped
2781 Georgi Kodinov 2009-07-14
Bug #46019: ERROR 1356 When selecting from within another
view that has Group By
Table access rights checking function check_grant() assumed
that no view is opened when it's called.
This is not true with nested views where the inner view
needs materialization. In this case the view is already
materialized when check_grant() is called for it.
This caused check_grant() to not look for table level
grants on the materialized view table.
Fixed by checking if a view is already materialized and if
it is check table level grants using the original table name
(not the ones of the materialized temp table).
modified:
mysql-test/r/view_grant.result
mysql-test/t/view_grant.test
sql/sql_acl.cc
=== modified file 'mysql-test/r/view_grant.result'
--- a/mysql-test/r/view_grant.result 2009-04-14 17:20:13 +0000
+++ b/mysql-test/r/view_grant.result 2009-07-14 15:57:27 +0000
@@ -945,4 +945,28 @@ DROP USER foo;
DROP VIEW db1.v1;
DROP TABLE db1.t1;
DROP DATABASE db1;
+#
+# Bug #46019: ERROR 1356 When selecting from within another
+# view that has Group By
+#
+CREATE DATABASE db1;
+USE db1;
+CREATE TABLE t1 (a INT);
+CREATE SQL SECURITY INVOKER VIEW v1 AS
+SELECT a FROM t1 GROUP BY a;
+CREATE SQL SECURITY INVOKER VIEW v2 AS
+SELECT a FROM v1;
+CREATE USER u1;
+GRANT SELECT ON TABLE t1 TO u1;
+GRANT SELECT, SHOW VIEW ON TABLE v1 TO u1;
+GRANT SELECT, SHOW VIEW ON TABLE v2 TO u1;
+SELECT a FROM v1;
+a
+SELECT a FROM v2;
+a
+DROP USER u1;
+DROP VIEW v1,v2;
+DROP TABLE t1;
+USE test;
+DROP DATABASE db1;
End of 5.0 tests.
=== modified file 'mysql-test/t/view_grant.test'
--- a/mysql-test/t/view_grant.test 2009-04-14 17:20:13 +0000
+++ b/mysql-test/t/view_grant.test 2009-07-14 15:57:27 +0000
@@ -1232,6 +1232,42 @@ DROP TABLE db1.t1;
DROP DATABASE db1;
connection default;
+
+--echo #
+--echo # Bug #46019: ERROR 1356 When selecting from within another
+--echo # view that has Group By
+--echo #
+
+CREATE DATABASE db1;
+USE db1;
+
+CREATE TABLE t1 (a INT);
+
+CREATE SQL SECURITY INVOKER VIEW v1 AS
+ SELECT a FROM t1 GROUP BY a;
+
+CREATE SQL SECURITY INVOKER VIEW v2 AS
+ SELECT a FROM v1;
+
+CREATE USER u1;
+
+GRANT SELECT ON TABLE t1 TO u1;
+GRANT SELECT, SHOW VIEW ON TABLE v1 TO u1;
+GRANT SELECT, SHOW VIEW ON TABLE v2 TO u1;
+
+CONNECT (u1, localhost, u1,,db1);
+CONNECTION u1;
+
+SELECT a FROM v1;
+SELECT a FROM v2;
+
+CONNECTION default;
+DISCONNECT u1;
+DROP USER u1;
+DROP VIEW v1,v2;
+DROP TABLE t1;
+USE test;
+DROP DATABASE db1;
--echo End of 5.0 tests.
# Wait till we reached the initial number of concurrent sessions
=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc 2009-06-17 13:54:01 +0000
+++ b/sql/sql_acl.cc 2009-07-14 15:57:27 +0000
@@ -3641,6 +3641,7 @@ bool check_grant(THD *thd, ulong want_ac
table= table->next_global)
{
GRANT_TABLE *grant_table;
+ char *table_name, *table_db;
sctx = test(table->security_ctx) ?
table->security_ctx : thd->security_ctx;
@@ -3650,11 +3651,14 @@ bool check_grant(THD *thd, ulong want_ac
continue; // ok
if (!(~table->grant.privilege & want_access) ||
- table->derived || table->schema_table)
+ (table->derived && !table->derived_result) || table->schema_table)
{
/*
It is subquery in the FROM clause. VIEW set table->derived after
- table opening, but this function always called before table opening.
+ table opening, but this function is mostly called before table opening.
+ When it's called after table opening e.g. for nested views with
+ materialization (table->derived_result present) we shoud check
+ the materialized table for access as any other table.
*/
if (!table->referencing_view)
{
@@ -3667,9 +3671,21 @@ bool check_grant(THD *thd, ulong want_ac
}
continue;
}
+
+ if (table->view)
+ {
+ table_name= table->view_name.str;
+ table_db= table->view_db.str;
+ }
+ else
+ {
+ table_name= table->table_name;
+ table_db= table->db;
+ }
+
if (!(grant_table= table_hash_search(sctx->host, sctx->ip,
- table->db, sctx->priv_user,
- table->table_name,0)))
+ table_db, sctx->priv_user,
+ table_name,0)))
{
want_access &= ~table->grant.privilege;
goto err; // No grants
Attachment: [text/bzr-bundle] bzr/joro@sun.com-20090714155727-tbs9gnsx32uypcpa.bundle
| Thread |
|---|
| • bzr commit into mysql-5.0-bugteam branch (joro:2781) Bug#46019 | Georgi Kodinov | 14 Jul |