Skip to content

Commit ff12ec8

Browse files
committed
MDEV-37483 mariadb-dump -T doesn't convert table names
use my_charset_filename to build file names from table names. this guarantees that file name will be always valid for any table name, no matter what characters it contains and what file name rules local filesystem has. mariadb-import now converts back, if possible.
1 parent 75b0003 commit ff12ec8

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

client/mysqldump.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,10 +1841,19 @@ static char *cover_definer_clause(const char *stmt_str,
18411841
static const char* build_path_for_table(char *to, const char *dir,
18421842
const char *table, const char *ext)
18431843
{
1844-
char tmp_path[FN_REFLEN];
1844+
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
18451845
convert_dirname(tmp_path, path, NULL);
18461846
my_load_path(tmp_path, tmp_path, NULL);
1847-
return fn_format(to, table, tmp_path, ext, MYF(MY_UNPACK_FILENAME));
1847+
if (check_if_legal_tablename(table))
1848+
strxnmov(filename, sizeof(filename) - 1, table, "@@@", NULL);
1849+
else
1850+
{
1851+
uint errors, len;
1852+
len= my_convert(filename, sizeof(filename) - 1, &my_charset_filename,
1853+
table, (uint32)strlen(table), charset_info, &errors);
1854+
filename[len]= 0;
1855+
}
1856+
return fn_format(to, filename, tmp_path, ext, MYF(MY_UNPACK_FILENAME));
18481857
}
18491858

18501859

client/mysqlimport.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,16 @@ static int write_to_table(char *filename, MYSQL *mysql)
340340
DBUG_PRINT("enter",("filename: %s",filename));
341341

342342
fn_format(tablename, filename, "", "", MYF(MY_REPLACE_DIR | MY_REPLACE_EXT));
343+
if (strchr(tablename, '@'))
344+
{
345+
uint errors, len;
346+
const char *csname= my_default_csname(); /* see MYSQL_SET_CHARSET_NAME */
347+
CHARSET_INFO *cs= get_charset_by_csname(csname, MY_CS_PRIMARY, MYF(0));
348+
len= my_convert(escaped_name, sizeof(escaped_name) - 1, cs, tablename,
349+
(uint32)strlen(tablename), &my_charset_filename, &errors);
350+
if (!errors)
351+
strmake(tablename, escaped_name, len);
352+
}
343353
if (!opt_local_file)
344354
strmov(hard_path,filename);
345355
else

mysql-test/main/mysqldump.result

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6624,3 +6624,49 @@ SET character_set_client = @saved_cs_client;
66246624
drop view `v'1"2`;
66256625
drop table t1;
66266626
# End of 10.5 tests
6627+
#
6628+
# MDEV-37483 mariadb-dump -T doesn't convert table names
6629+
#
6630+
set names latin1;
6631+
create database foo;
6632+
use foo;
6633+
create table `con_sch�ne_gr��e` (a int) select 1 as a;
6634+
create table `con` (b int) select 2 as b;
6635+
create table `con/bar` (c int) select 3 as c;
6636+
create table `con@home` (d int) select 4 as d;
6637+
drop database foo;
6638+
use test;
6639+
con@002fbar.sql
6640+
con@002fbar.txt
6641+
con@@@.sql
6642+
con@@@.txt
6643+
con@home.sql
6644+
con@home.txt
6645+
con_sch@1ine_gr@1o@1je.sql
6646+
con_sch@1ine_gr@1o@1je.txt
6647+
show tables;
6648+
Tables_in_test
6649+
con
6650+
con/bar
6651+
con@home
6652+
con_sch�ne_gr��e
6653+
test.con: Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
6654+
test.con/bar: Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
6655+
test.con@home: Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
6656+
select * from `con_sch�ne_gr��e`;
6657+
a
6658+
1
6659+
select * from `con`;
6660+
b
6661+
2
6662+
select * from `con/bar`;
6663+
c
6664+
3
6665+
select * from `con@home`;
6666+
d
6667+
4
6668+
drop table `con_sch�ne_gr��e`;
6669+
drop table `con`;
6670+
drop table `con/bar`;
6671+
drop table `con@home`;
6672+
# End of 10.6 tests

mysql-test/main/mysqldump.test

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,3 +3035,45 @@ drop view `v'1"2`; # "'
30353035
drop table t1;
30363036

30373037
--echo # End of 10.5 tests
3038+
3039+
--echo #
3040+
--echo # MDEV-37483 mariadb-dump -T doesn't convert table names
3041+
--echo #
3042+
set names latin1;
3043+
create database foo;
3044+
use foo;
3045+
3046+
create table `con_sch�ne_gr��e` (a int) select 1 as a;
3047+
create table `con` (b int) select 2 as b;
3048+
create table `con/bar` (c int) select 3 as c;
3049+
create table `con@home` (d int) select 4 as d;
3050+
exec $MYSQL_DUMP foo --tab $MYSQLTEST_VARDIR/tmp;
3051+
drop database foo;
3052+
use test;
3053+
move_file $MYSQLTEST_VARDIR/tmp/con@0040home.sql $MYSQLTEST_VARDIR/tmp/con@home.sql;
3054+
move_file $MYSQLTEST_VARDIR/tmp/con@0040home.txt $MYSQLTEST_VARDIR/tmp/con@home.txt;
3055+
list_files $MYSQLTEST_VARDIR/tmp con*;
3056+
exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/con@@@.sql;
3057+
exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/con@002fbar.sql;
3058+
exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/con_sch@1ine_gr@1o@1je.sql;
3059+
exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/con@home.sql;
3060+
show tables;
3061+
exec $MYSQL_IMPORT test $MYSQLTEST_VARDIR/tmp/con@@@.txt;
3062+
exec $MYSQL_IMPORT test $MYSQLTEST_VARDIR/tmp/con@002fbar.txt;
3063+
if (`select @@version like '10.6.%'`) {
3064+
# utf8 console output on Windows is fixed in MDEV-26713, until then
3065+
--disable_result_log
3066+
}
3067+
exec $MYSQL_IMPORT test $MYSQLTEST_VARDIR/tmp/con_sch@1ine_gr@1o@1je.txt;
3068+
--enable_result_log
3069+
exec $MYSQL_IMPORT test $MYSQLTEST_VARDIR/tmp/con@home.txt;
3070+
select * from `con_sch�ne_gr��e`;
3071+
select * from `con`;
3072+
select * from `con/bar`;
3073+
select * from `con@home`;
3074+
drop table `con_sch�ne_gr��e`;
3075+
drop table `con`;
3076+
drop table `con/bar`;
3077+
drop table `con@home`;
3078+
3079+
--echo # End of 10.6 tests

0 commit comments

Comments
 (0)