Skip to content

Commit 985e3df

Browse files
committed
MDEV-33182 Server assertion fails when trying to test the connection with DBeaver
Some connectors (JDBC, Node.js) can sent non-default collation IDs in the handshake packet. The code in thd_init_client_charset() handling @@character_set_collations did not expect that and crashed on DBUG_ASSERT. Changing the code to ignore @@character_set_collations in case of non-default IDs. This fixes the problem in a backward compatible (with pre-@@character_set_collations server versions) way for such connectors sending non-default IDs.
1 parent 468d29f commit 985e3df

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

mysql-test/main/connect_debug.result

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,23 @@ connect(localhost,root,,test,MASTER_MYPORT,MYSQL_TMP_DIR/mysqld.1.sock);
1818
connect con2,localhost,root;
1919
ERROR HY000: Received malformed packet
2020
set global debug_dbug=@old_dbug;
21+
#
22+
# Start of 11.2 tests
23+
#
24+
#
25+
# MDEV-33182 Server assertion fails when trying to test the connection with DBeaver
26+
#
27+
SET global debug_dbug='+d,thd_init_client_charset_utf8mb3_bin';
28+
connect con1,localhost,root;
29+
connection con1;
30+
SHOW VARIABLES LIKE 'collation%';
31+
Variable_name Value
32+
collation_connection utf8mb3_bin
33+
collation_database latin1_swedish_ci
34+
collation_server latin1_swedish_ci
35+
disconnect con1;
36+
connection default;
37+
SET global debug_dbug=@old_debug;
38+
#
39+
# End of 11.2 tests
40+
#

mysql-test/main/connect_debug.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,24 @@ set global debug_dbug='+d,poison_srv_handshake_scramble_len';
3737
--error 2027
3838
connect con2,localhost,root;
3939
set global debug_dbug=@old_dbug;
40+
41+
42+
--echo #
43+
--echo # Start of 11.2 tests
44+
--echo #
45+
46+
--echo #
47+
--echo # MDEV-33182 Server assertion fails when trying to test the connection with DBeaver
48+
--echo #
49+
50+
SET global debug_dbug='+d,thd_init_client_charset_utf8mb3_bin';
51+
connect con1,localhost,root;
52+
connection con1;
53+
SHOW VARIABLES LIKE 'collation%';
54+
disconnect con1;
55+
connection default;
56+
SET global debug_dbug=@old_debug;
57+
58+
--echo #
59+
--echo # End of 11.2 tests
60+
--echo #

sql/sql_connect.cc

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,10 @@ void update_global_user_stats(THD *thd, bool create_user, time_t now)
779779
bool thd_init_client_charset(THD *thd, uint cs_number)
780780
{
781781
CHARSET_INFO *cs;
782+
783+
// Test a non-default collation ID. See also comments in this function below.
784+
DBUG_EXECUTE_IF("thd_init_client_charset_utf8mb3_bin", cs_number= 83;);
785+
782786
/*
783787
Use server character set and collation if
784788
- opt_character_set_client_handshake is not set
@@ -801,9 +805,25 @@ bool thd_init_client_charset(THD *thd, uint cs_number)
801805
cs->cs_name.str);
802806
return true;
803807
}
804-
Sql_used used;
805-
cs= global_system_variables.character_set_collations.
806-
get_collation_for_charset(&used, cs);
808+
/*
809+
Some connectors (e.g. JDBC, Node.js) can send non-default collation IDs
810+
in the handshake packet, to set @@collation_connection right during
811+
handshake. Although this is a non-documenting feature,
812+
for better backward compatibility with such connectors let's:
813+
a. resolve only default collations according to @@character_set_collations
814+
b. preserve non-default collations as is
815+
816+
Perhaps eventually we should change (b) also to resolve non-default
817+
collations accoding to @@character_set_collations. Clients that used to
818+
send a non-default collation ID in the handshake packet will have to set
819+
@@character_set_collations instead.
820+
*/
821+
if (cs->state & MY_CS_PRIMARY)
822+
{
823+
Sql_used used;
824+
cs= global_system_variables.character_set_collations.
825+
get_collation_for_charset(&used, cs);
826+
}
807827
thd->org_charset= cs;
808828
thd->update_charset(cs,cs,cs);
809829
}

0 commit comments

Comments
 (0)