Skip to content

Commit

Permalink
MDEV-6128:[PATCH] mysqlcheck wrongly escapes '.' in table names
Browse files Browse the repository at this point in the history
Backport from mysql 5.7. The patch reviewed, test added.
  • Loading branch information
unknown committed Jan 28, 2015
1 parent cb9c116 commit 9033aa0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
34 changes: 21 additions & 13 deletions client/mysqlcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,6 @@ static uint fixed_name_length(const char *name)
{
if (*p == '`')
extra_length++;
else if (*p == '.')
extra_length+= 2;

}
DBUG_RETURN((uint) ((p - name) + extra_length));
}
Expand All @@ -530,11 +527,6 @@ static char *fix_table_name(char *dest, char *src)
for (; *src; src++)
{
switch (*src) {
case '.': /* add backticks around '.' */
*dest++= '`';
*dest++= '.';
*dest++= '`';
break;
case '`': /* escape backtick character */
*dest++= '`';
/* fall through */
Expand Down Expand Up @@ -818,13 +810,17 @@ static void print_result()
{
MYSQL_RES *res;
MYSQL_ROW row;
char prev[(NAME_LEN+9)*2+2];
char prev[(NAME_LEN+9)*3+2];
char prev_alter[MAX_ALTER_STR_SIZE];
char *db_name;
uint length_of_db;
uint i;
my_bool found_error=0, table_rebuild=0;
DBUG_ENTER("print_result");

res = mysql_use_result(sock);
db_name= sock->db;
length_of_db= strlen(db_name);

prev[0] = '\0';
prev_alter[0]= 0;
Expand All @@ -848,10 +844,16 @@ static void print_result()
if (prev_alter[0])
insert_dynamic(&alter_table_cmds, (uchar*) prev_alter);
else
insert_dynamic(&tables4rebuild, (uchar*) prev);
{
char *table_name= prev + (length_of_db+1);
insert_dynamic(&tables4rebuild, (uchar*) table_name);
}
}
else
insert_dynamic(&tables4repair, (uchar*) prev);
{
char *table_name= prev + (length_of_db+1);
insert_dynamic(&tables4repair, (uchar*) table_name);
}
}
found_error=0;
table_rebuild=0;
Expand Down Expand Up @@ -911,10 +913,16 @@ static void print_result()
if (prev_alter[0])
insert_dynamic(&alter_table_cmds, (uchar*) prev_alter);
else
insert_dynamic(&tables4rebuild, (uchar*) prev);
{
char *table_name= prev + (length_of_db+1);
insert_dynamic(&tables4rebuild, (uchar*) table_name);
}
}
else
insert_dynamic(&tables4repair, (uchar*) prev);
{
char *table_name= prev + (length_of_db+1);
insert_dynamic(&tables4repair, (uchar*) table_name);
}
}
mysql_free_result(res);
DBUG_VOID_RETURN;
Expand Down
11 changes: 9 additions & 2 deletions mysql-test/r/mysqlcheck.result
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DROP TABLE IF EXISTS t1, `t``1`, `t 1`;
drop view if exists v1;
DROP TABLE IF EXISTS t1, `t``1`, `t 1`, test.`t.1`, v1;
drop view if exists t1, `t``1`, `t 1`, test.`t.1`, v1;
drop database if exists client_test_db;
mtr.global_suppressions OK
mtr.test_suppressions OK
Expand Down Expand Up @@ -309,3 +309,10 @@ CHECK TABLE bug47205 FOR UPGRADE;
Table Op Msg_type Msg_text
test.bug47205 check status OK
DROP TABLE bug47205;
#
#MDEV-6128:[PATCH] mysqlcheck wrongly escapes '.' in table names
#
CREATE TABLE test.`t.1` (id int);
mysqlcheck test t.1
test.t.1 OK
drop table test.`t.1`;
14 changes: 12 additions & 2 deletions mysql-test/t/mysqlcheck.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#

--disable_warnings
DROP TABLE IF EXISTS t1, `t``1`, `t 1`;
drop view if exists v1;
DROP TABLE IF EXISTS t1, `t``1`, `t 1`, test.`t.1`, v1;
drop view if exists t1, `t``1`, `t 1`, test.`t.1`, v1;
drop database if exists client_test_db;
# Repair any tables in mysql, sometimes the slow_log is marked as crashed
# after server has been killed
Expand Down Expand Up @@ -313,3 +313,13 @@ CHECK TABLE bug47205 FOR UPGRADE;
CHECK TABLE bug47205 FOR UPGRADE;

DROP TABLE bug47205;

--echo #
--echo #MDEV-6128:[PATCH] mysqlcheck wrongly escapes '.' in table names
--echo #
CREATE TABLE test.`t.1` (id int);

--echo mysqlcheck test t.1
--exec $MYSQL_CHECK test t.1

drop table test.`t.1`;

0 comments on commit 9033aa0

Please sign in to comment.