Commit 985e3dfc authored by Alexander Barkov's avatar Alexander Barkov

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.
parent 468d29f8
......@@ -18,3 +18,23 @@ connect(localhost,root,,test,MASTER_MYPORT,MYSQL_TMP_DIR/mysqld.1.sock);
connect con2,localhost,root;
ERROR HY000: Received malformed packet
set global debug_dbug=@old_dbug;
#
# Start of 11.2 tests
#
#
# MDEV-33182 Server assertion fails when trying to test the connection with DBeaver
#
SET global debug_dbug='+d,thd_init_client_charset_utf8mb3_bin';
connect con1,localhost,root;
connection con1;
SHOW VARIABLES LIKE 'collation%';
Variable_name Value
collation_connection utf8mb3_bin
collation_database latin1_swedish_ci
collation_server latin1_swedish_ci
disconnect con1;
connection default;
SET global debug_dbug=@old_debug;
#
# End of 11.2 tests
#
......@@ -37,3 +37,24 @@ set global debug_dbug='+d,poison_srv_handshake_scramble_len';
--error 2027
connect con2,localhost,root;
set global debug_dbug=@old_dbug;
--echo #
--echo # Start of 11.2 tests
--echo #
--echo #
--echo # MDEV-33182 Server assertion fails when trying to test the connection with DBeaver
--echo #
SET global debug_dbug='+d,thd_init_client_charset_utf8mb3_bin';
connect con1,localhost,root;
connection con1;
SHOW VARIABLES LIKE 'collation%';
disconnect con1;
connection default;
SET global debug_dbug=@old_debug;
--echo #
--echo # End of 11.2 tests
--echo #
......@@ -779,6 +779,10 @@ void update_global_user_stats(THD *thd, bool create_user, time_t now)
bool thd_init_client_charset(THD *thd, uint cs_number)
{
CHARSET_INFO *cs;
// Test a non-default collation ID. See also comments in this function below.
DBUG_EXECUTE_IF("thd_init_client_charset_utf8mb3_bin", cs_number= 83;);
/*
Use server character set and collation if
- opt_character_set_client_handshake is not set
......@@ -801,9 +805,25 @@ bool thd_init_client_charset(THD *thd, uint cs_number)
cs->cs_name.str);
return true;
}
/*
Some connectors (e.g. JDBC, Node.js) can send non-default collation IDs
in the handshake packet, to set @@collation_connection right during
handshake. Although this is a non-documenting feature,
for better backward compatibility with such connectors let's:
a. resolve only default collations according to @@character_set_collations
b. preserve non-default collations as is
Perhaps eventually we should change (b) also to resolve non-default
collations accoding to @@character_set_collations. Clients that used to
send a non-default collation ID in the handshake packet will have to set
@@character_set_collations instead.
*/
if (cs->state & MY_CS_PRIMARY)
{
Sql_used used;
cs= global_system_variables.character_set_collations.
get_collation_for_charset(&used, cs);
}
thd->org_charset= cs;
thd->update_charset(cs,cs,cs);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment