Skip to content

Commit 7849a27

Browse files
Dyre TjeldvollDyre Tjeldvoll
authored andcommitted
Bug#25514146: DB_NAME IS IGNORED WHEN CREATING TABLE WITH DATA DIRECTORY
Problem: CREATE TABLE using a fully qualified name with INDEX DIR/DATA DIR option reports an error when the current database is not SET. check_access() was incorrectly called with NULL as the database argument in a situation where the database name was not needed for the particular privilege being checked. This will cause the current database to be used, or an error to be reported if there is no current database. Fix: Call check_access() with any_db as the database argument in this situation.
1 parent b21a021 commit 7849a27

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

mysql-test/r/symlink.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,14 @@ t2 CREATE TABLE `t2` (
213213
PRIMARY KEY (`a`)
214214
) ENGINE=MyISAM DEFAULT CHARSET=latin1
215215
drop tables t1, t2;
216+
#
217+
# Test for bug #25514146 DB_NAME IS IGNORED WHEN CREATING TABLE
218+
# WITH DATA DIRECTORY
219+
#
220+
# Make sure we have no current database
221+
CREATE DATABASE x;
222+
USE x;
223+
DROP DATABASE x;
224+
CREATE TABLE test.t1(id INT(11)) ENGINE MYISAM
225+
DATA DIRECTORY "MYSQLTEST_VARDIR/tmp";
226+
DROP TABLE test.t1;

mysql-test/t/symlink.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,19 @@ show create table t1;
298298
create table t2 like t1;
299299
show create table t2;
300300
drop tables t1, t2;
301+
302+
--echo #
303+
--echo # Test for bug #25514146 DB_NAME IS IGNORED WHEN CREATING TABLE
304+
--echo # WITH DATA DIRECTORY
305+
--echo #
306+
307+
--echo # Make sure we have no current database
308+
CREATE DATABASE x;
309+
USE x;
310+
DROP DATABASE x;
311+
312+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
313+
eval CREATE TABLE test.t1(id INT(11)) ENGINE MYISAM
314+
DATA DIRECTORY "$MYSQLTEST_VARDIR/tmp";
315+
316+
DROP TABLE test.t1;

sql/sql_parse.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -2425,7 +2425,7 @@ case SQLCOM_PREPARE:
24252425

24262426
if (((lex->create_info.used_fields & HA_CREATE_USED_DATADIR) != 0 ||
24272427
(lex->create_info.used_fields & HA_CREATE_USED_INDEXDIR) != 0) &&
2428-
check_access(thd, FILE_ACL, NULL, NULL, NULL, FALSE, FALSE))
2428+
check_access(thd, FILE_ACL, any_db, NULL, NULL, FALSE, FALSE))
24292429
{
24302430
res= 1;
24312431
my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "FILE");
@@ -2470,7 +2470,7 @@ case SQLCOM_PREPARE:
24702470
{
24712471
partition_info *part_info= thd->lex->part_info;
24722472
if (part_info != NULL && has_external_data_or_index_dir(*part_info) &&
2473-
check_access(thd, FILE_ACL, NULL, NULL, NULL, FALSE, FALSE))
2473+
check_access(thd, FILE_ACL, any_db, NULL, NULL, FALSE, FALSE))
24742474
{
24752475
res= -1;
24762476
goto end_with_restore_list;

0 commit comments

Comments
 (0)