Skip to content

Commit

Permalink
MDEV-13187 incorrect backslash parsing in clients
Browse files Browse the repository at this point in the history
don't do backslash escapes inside backticks
  • Loading branch information
vuvova committed Jun 27, 2017
1 parent ded614d commit 39385ff
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2287,8 +2287,8 @@ static bool add_line(String &buffer, char *line, ulong line_length,
continue;
}
#endif
if (!*ml_comment && inchar == '\\' &&
!(*in_string &&
if (!*ml_comment && inchar == '\\' && *in_string != '`' &&
!(*in_string &&
(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)))
{
// Found possbile one character command like \c
Expand Down
4 changes: 2 additions & 2 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6594,7 +6594,7 @@ int read_line(char *buf, int size)
state= R_Q;
}
}
have_slash= (c == '\\');
have_slash= (c == '\\' && last_quote != '`');
break;

case R_COMMENT:
Expand Down Expand Up @@ -6664,7 +6664,7 @@ int read_line(char *buf, int size)
case R_Q:
if (c == last_quote)
state= R_NORMAL;
else if (c == '\\')
else if (c == '\\' && last_quote != '`')
state= R_SLASH_IN_Q;
break;

Expand Down
28 changes: 28 additions & 0 deletions mysql-test/r/mysql.result
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,31 @@ a
+-------------------+

End of tests
create table `a1\``b1` (a int);
show tables;
Tables_in_test
a1\`b1
insert `a1\``b1` values (1),(2);
show create table `a1\``b1`;
Table Create Table
a1\`b1 CREATE TABLE `a1\``b1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `a1\``b1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO `a1\``b1` VALUES (1),(2);
insert `a1\``b1` values (4),(5);
show create table `a1\``b1`;
Table Create Table
a1\`b1 CREATE TABLE `a1\``b1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from `a1\``b1`;
a
1
2
drop table `a1\``b1`;
15 changes: 15 additions & 0 deletions mysql-test/t/mysql.test
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,18 @@ EOF

--echo
--echo End of tests

#
# MDEV-13187 incorrect backslash parsing in clients
#
create table `a1\``b1` (a int);
show tables;
insert `a1\``b1` values (1),(2);
show create table `a1\``b1`;
--exec $MYSQL_DUMP --compact test
--exec $MYSQL_DUMP test > $MYSQLTEST_VARDIR/tmp/bug.sql
insert `a1\``b1` values (4),(5);
--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug.sql
show create table `a1\``b1`;
select * from `a1\``b1`;
drop table `a1\``b1`;

0 comments on commit 39385ff

Please sign in to comment.