Skip to content

Commit 047eb22

Browse files
author
Alexey Botchkov
committed
MDEV-25141 JSON_TABLE: SELECT into outfile bypasses file privilege check.
access rights checking fixed.
1 parent abdc39b commit 047eb22

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

mysql-test/suite/json/r/json_table.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ a
111111
select * from t, json_table(t.a, '$' columns(f varchar(20) path '$.foo')) as jt;
112112
a f
113113
{"foo":"bar"} bar
114+
select * into outfile 'f' from json_table('[]', '$' columns(x for ordinality)) q;
115+
ERROR 28000: Access denied for user 'u'@'localhost' (using password: NO)
114116
connection default;
115117
disconnect con1;
116118
drop user u@localhost;

mysql-test/suite/json/t/json_table.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ grant select (a) on db.t to u@localhost;
7474
select a from t;
7575
select * from t, json_table(t.a, '$' columns(f varchar(20) path '$.foo')) as jt;
7676

77+
#
78+
# MDEV-25141 JSON_TABLE: SELECT into outfile bypasses file privilege check
79+
#
80+
--error ER_ACCESS_DENIED_ERROR
81+
select * into outfile 'f' from json_table('[]', '$' columns(x for ordinality)) q;
82+
7783
connection default;
7884
disconnect con1;
7985

sql/sql_acl.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8150,16 +8150,9 @@ bool check_grant(THD *thd, privilege_t want_access, TABLE_LIST *tables,
81508150
if (!want_access)
81518151
continue; // ok
81528152

8153-
if (t_ref->table_function)
8154-
{
8155-
/* Table function doesn't need any privileges to be checked. */
8156-
t_ref->grant.privilege|= TMP_TABLE_ACLS;
8157-
t_ref->grant.want_privilege= NO_ACL;
8158-
continue;
8159-
}
8160-
81618153
if (!(~t_ref->grant.privilege & want_access) ||
8162-
t_ref->is_anonymous_derived_table() || t_ref->schema_table)
8154+
t_ref->is_anonymous_derived_table() || t_ref->schema_table ||
8155+
t_ref->table_function)
81638156
{
81648157
/*
81658158
It is subquery in the FROM clause. VIEW set t_ref->derived after
@@ -8168,7 +8161,8 @@ bool check_grant(THD *thd, privilege_t want_access, TABLE_LIST *tables,
81688161
NOTE: is_derived() can't be used here because subquery in this case
81698162
the FROM clase (derived tables) can be not be marked yet.
81708163
*/
8171-
if (t_ref->is_anonymous_derived_table() || t_ref->schema_table)
8164+
if (t_ref->is_anonymous_derived_table() || t_ref->schema_table ||
8165+
t_ref->table_function)
81728166
{
81738167
/*
81748168
If it's a temporary table created for a subquery in the FROM

sql/sql_parse.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7104,9 +7104,6 @@ check_table_access(THD *thd, privilege_t requirements, TABLE_LIST *tables,
71047104
if (table_ref->is_anonymous_derived_table())
71057105
continue;
71067106

7107-
if (table_ref->table_function)
7108-
continue;
7109-
71107107
if (table_ref->sequence)
71117108
{
71127109
/* We want to have either SELECT or INSERT rights to sequences depending
@@ -7116,7 +7113,9 @@ check_table_access(THD *thd, privilege_t requirements, TABLE_LIST *tables,
71167113
INSERT_ACL : SELECT_ACL);
71177114
}
71187115

7119-
if (check_access(thd, want_access, table_ref->get_db_name(),
7116+
if (check_access(thd, want_access,
7117+
table_ref->table_function ? any_db :
7118+
table_ref->get_db_name(),
71207119
&table_ref->grant.privilege,
71217120
&table_ref->grant.m_internal,
71227121
0, no_errors))

0 commit comments

Comments
 (0)