Bug #103733 Connection Attributes will be disappeared after com_change_user
Submitted: 19 May 2021 7:16 Modified: 19 May 2021 9:40
Reporter: Huqing Yan (OCA) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.7.34 OS:Any
Assigned to: CPU Architecture:Any
Tags: Com_change_user

[19 May 2021 7:16] Huqing Yan
Description:
Connection Attributes will be disappeared after com_change_user 

How to repeat:
use these java code:

Class.forName("com.mysql.cj.jdbc.Driver");
            Connection connectionPrepare = DriverManager.getConnection(
                    "jdbc:mysql://127.0.0.1:3306/?connectionAttributes=key1:value1", "root", "123456");
            //breakpoint 1
            MysqlPooledConnection pool = new MysqlPooledConnection((com.mysql.cj.jdbc.JdbcConnection) connectionPrepare);
            Connection connection = pool.getConnection();
            //breakpoint 2
            ...

When run to breakpoint1, you can see attributes  by `select * from performance_schema.session_connect_attrs`;

when run to breakpoint2, the result will be disappeared.

Suggested fix:
--- a/sql/auth/sql_authentication.cc
+++ b/sql/auth/sql_authentication.cc
@@ -1116,6 +1116,7 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, size_t packet_length)
       my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
       DBUG_RETURN(1);
     }
+    ptr = ptr + 2 + strlen(client_plugin) + 1;
   }
   else
     client_plugin= native_password_plugin_name.str;

ptr will point to the correct position
[19 May 2021 7:21] Huqing Yan
patch.diff

Attachment: patch.diff (application/octet-stream, text), 473 bytes.

[19 May 2021 7:54] Huqing Yan
this path will make sense

Attachment: patch57.diff (application/octet-stream, text), 971 bytes.

[19 May 2021 9:03] Huqing Yan
diff --git a/sql/auth/sql_authentication.cc b/sql/auth/sql_authentication.cc
--- a/sql/auth/sql_authentication.cc
+++ b/sql/auth/sql_authentication.cc
@@ -1067,6 +1067,7 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, size_t packet_length)
   {
     if (mpvio->charset_adapter->init_client_charset(uint2korr(ptr)))
       DBUG_RETURN(1);
+    ptr= ptr + 2;
   }
 
   /* Convert database and user names to utf8 */
@@ -1110,12 +1111,13 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, size_t packet_length)
   const char *client_plugin;
   if (protocol->has_client_capability(CLIENT_PLUGIN_AUTH))
   {
-    client_plugin= ptr + 2;
+    client_plugin= ptr;
     if (client_plugin >= end)
     {
       my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
       DBUG_RETURN(1);
     }
+    ptr= ptr + strlen(client_plugin) + 1;
   }
   else
     client_plugin= native_password_plugin_name.str;
[19 May 2021 9:40] MySQL Verification Team
Hello Huqing Yan,

Thank you for the report and contribution.
Imho this is duplicate of Bug #102266, we hope you add your comments to the original bug instead. Please ensure to re-send the patch "contribution" that tab in the base bug. Otherwise we would not be able to accept it. Thank you!

regards,
Umesh