Skip to content

Commit d3cc15e

Browse files
committed
Merge branch '10.0' into 10.1
2 parents b503b1c + 92928bc commit d3cc15e

File tree

10 files changed

+126
-7
lines changed

10 files changed

+126
-7
lines changed

client/mysql.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,8 +2319,10 @@ static bool add_line(String &buffer, char *line, ulong line_length,
23192319
continue;
23202320
}
23212321
#endif
2322-
if (!*ml_comment && inchar == '\\' &&
2323-
!(*in_string &&
2322+
if (!*ml_comment && inchar == '\\' && *in_string != '`' &&
2323+
!(*in_string == '"' &&
2324+
(mysql.server_status & SERVER_STATUS_ANSI_QUOTES)) &&
2325+
!(*in_string &&
23242326
(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)))
23252327
{
23262328
// Found possbile one character command like \c

client/mysqltest.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6520,6 +6520,16 @@ my_bool end_of_query(int c)
65206520
}
65216521

65226522

6523+
static inline bool is_escape_char(char c, char in_string)
6524+
{
6525+
if (c != '\\' || in_string == '`') return false;
6526+
if (!cur_con) return true;
6527+
uint server_status= cur_con->mysql->server_status;
6528+
if (server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) return false;
6529+
return !(server_status & SERVER_STATUS_ANSI_QUOTES && in_string == '"');
6530+
}
6531+
6532+
65236533
/*
65246534
Read one "line" from the file
65256535
@@ -6546,7 +6556,7 @@ my_bool end_of_query(int c)
65466556

65476557
int read_line(char *buf, int size)
65486558
{
6549-
char c, UNINIT_VAR(last_quote), last_char= 0;
6559+
char c, last_quote=0, last_char= 0;
65506560
char *p= buf, *buf_end= buf + size - 1;
65516561
int skip_char= 0;
65526562
my_bool have_slash= FALSE;
@@ -6628,7 +6638,7 @@ int read_line(char *buf, int size)
66286638
state= R_Q;
66296639
}
66306640
}
6631-
have_slash= (c == '\\');
6641+
have_slash= is_escape_char(c, last_quote);
66326642
break;
66336643

66346644
case R_COMMENT:
@@ -6698,7 +6708,7 @@ int read_line(char *buf, int size)
66986708
case R_Q:
66996709
if (c == last_quote)
67006710
state= R_NORMAL;
6701-
else if (c == '\\')
6711+
else if (is_escape_char(c, last_quote))
67026712
state= R_SLASH_IN_Q;
67036713
break;
67046714

include/mysql_com.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ enum enum_server_command
323323
*/
324324
#define SERVER_STATUS_IN_TRANS_READONLY 8192
325325

326+
#define SERVER_STATUS_ANSI_QUOTES 32768
327+
326328

327329
/**
328330
Server status flags that must be cleared when starting

mysql-test/r/mysql.result

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,61 @@ ERROR 1300 (HY000) at line 2: Invalid utf8 character string: 'test\xF0\x9F\x98\x
544544
set GLOBAL sql_mode=default;
545545

546546
End of tests
547+
create table `a1\``b1` (a int);
548+
show tables;
549+
Tables_in_test
550+
a1\`b1
551+
insert `a1\``b1` values (1),(2);
552+
show create table `a1\``b1`;
553+
Table Create Table
554+
a1\`b1 CREATE TABLE `a1\``b1` (
555+
`a` int(11) DEFAULT NULL
556+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
557+
/*!40101 SET @saved_cs_client = @@character_set_client */;
558+
/*!40101 SET character_set_client = utf8 */;
559+
CREATE TABLE `a1\``b1` (
560+
`a` int(11) DEFAULT NULL
561+
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
562+
/*!40101 SET character_set_client = @saved_cs_client */;
563+
INSERT INTO `a1\``b1` VALUES (1),(2);
564+
insert `a1\``b1` values (4),(5);
565+
show create table `a1\``b1`;
566+
Table Create Table
567+
a1\`b1 CREATE TABLE `a1\``b1` (
568+
`a` int(11) DEFAULT NULL
569+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
570+
select * from `a1\``b1`;
571+
a
572+
1
573+
2
574+
drop table `a1\``b1`;
575+
set sql_mode=ansi_quotes;
576+
create table "a1\""b1" (a int);
577+
show tables;
578+
Tables_in_test
579+
a1\"b1
580+
insert "a1\""b1" values (1),(2);
581+
show create table "a1\""b1";
582+
Table Create Table
583+
a1\"b1 CREATE TABLE "a1\""b1" (
584+
"a" int(11) DEFAULT NULL
585+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
586+
/*!40101 SET @saved_cs_client = @@character_set_client */;
587+
/*!40101 SET character_set_client = utf8 */;
588+
CREATE TABLE "a1\""b1" (
589+
"a" int(11) DEFAULT NULL
590+
);
591+
/*!40101 SET character_set_client = @saved_cs_client */;
592+
INSERT INTO "a1\""b1" VALUES (1),(2);
593+
insert "a1\""b1" values (4),(5);
594+
show create table "a1\""b1";
595+
Table Create Table
596+
a1\"b1 CREATE TABLE "a1\""b1" (
597+
"a" int(11) DEFAULT NULL
598+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
599+
select * from "a1\""b1";
600+
a
601+
1
602+
2
603+
drop table "a1\""b1";
604+
set sql_mode=default;

mysql-test/r/mysqltest.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,4 +962,9 @@ con1
962962
con2
963963
con2
964964
-closed_connection-
965+
set sql_mode=no_backslash_escapes;
966+
select "foo\""bar";
967+
foo\"bar
968+
foo\"bar
969+
set sql_mode=default;
965970
End of tests

mysql-test/t/mysql.test

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,3 +645,33 @@ EOF
645645
set GLOBAL sql_mode=default;
646646
--echo
647647
--echo End of tests
648+
649+
#
650+
# MDEV-13187 incorrect backslash parsing in clients
651+
#
652+
create table `a1\``b1` (a int);
653+
show tables;
654+
insert `a1\``b1` values (1),(2);
655+
show create table `a1\``b1`;
656+
--exec $MYSQL_DUMP --compact test
657+
--exec $MYSQL_DUMP test > $MYSQLTEST_VARDIR/tmp/bug.sql
658+
insert `a1\``b1` values (4),(5);
659+
--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug.sql
660+
show create table `a1\``b1`;
661+
select * from `a1\``b1`;
662+
drop table `a1\``b1`;
663+
664+
# same with ansi_quotes
665+
set sql_mode=ansi_quotes;
666+
create table "a1\""b1" (a int);
667+
show tables;
668+
insert "a1\""b1" values (1),(2);
669+
show create table "a1\""b1";
670+
--exec $MYSQL_DUMP --compact --compatible=postgres test
671+
--exec $MYSQL_DUMP --compatible=postgres test > $MYSQLTEST_VARDIR/tmp/bug.sql
672+
insert "a1\""b1" values (4),(5);
673+
--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug.sql
674+
show create table "a1\""b1";
675+
select * from "a1\""b1";
676+
drop table "a1\""b1";
677+
set sql_mode=default;

mysql-test/t/mysqltest.test

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2946,11 +2946,17 @@ disconnect $x;
29462946
# Disconnect the selected connection
29472947
disconnect $y;
29482948
--echo $CURRENT_CONNECTION
2949+
connection default;
29492950

2951+
#
2952+
# MDEV-13187 incorrect backslash parsing in clients
2953+
#
2954+
set sql_mode=no_backslash_escapes;
2955+
select "foo\""bar";
2956+
set sql_mode=default;
29502957

29512958
--echo End of tests
29522959

2953-
connection default;
29542960
# Wait till we reached the initial number of concurrent sessions
29552961
--source include/wait_until_count_sessions.inc
29562962

sql/item_strfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ String *Item_func_reverse::val_str(String *str)
11001100
if ((l= my_ismbchar(res->charset(),ptr,end)))
11011101
{
11021102
tmp-= l;
1103-
DBUG_ASSERT(tmp >= tmp_value.ptr());
1103+
DBUG_ASSERT(tmp >= str->ptr());
11041104
memcpy(tmp,ptr,l);
11051105
ptr+= l;
11061106
}

sql/sql_class.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,8 @@ void THD::init(void)
14001400
server_status= SERVER_STATUS_AUTOCOMMIT;
14011401
if (variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)
14021402
server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;
1403+
if (variables.sql_mode & MODE_ANSI_QUOTES)
1404+
server_status|= SERVER_STATUS_ANSI_QUOTES;
14031405

14041406
transaction.all.modified_non_trans_table=
14051407
transaction.stmt.modified_non_trans_table= FALSE;

sql/sys_vars.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,6 +3030,10 @@ static bool fix_sql_mode(sys_var *self, THD *thd, enum_var_type type)
30303030
thd->server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;
30313031
else
30323032
thd->server_status&= ~SERVER_STATUS_NO_BACKSLASH_ESCAPES;
3033+
if (thd->variables.sql_mode & MODE_ANSI_QUOTES)
3034+
thd->server_status|= SERVER_STATUS_ANSI_QUOTES;
3035+
else
3036+
thd->server_status&= ~SERVER_STATUS_ANSI_QUOTES;
30333037
}
30343038
return false;
30353039
}

0 commit comments

Comments
 (0)