Commit 261ce528 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-18281 COM_RESET_CONNECTION changes the connection encoding

Store original charset during client authentication, and restore it for
COM_RESET_CONNECTION
parent 915ed7e6
...@@ -5938,6 +5938,7 @@ void do_connect(struct st_command *command) ...@@ -5938,6 +5938,7 @@ void do_connect(struct st_command *command)
int read_timeout= 0; int read_timeout= 0;
int write_timeout= 0; int write_timeout= 0;
int connect_timeout= 0; int connect_timeout= 0;
char *csname=0;
struct st_connection* con_slot; struct st_connection* con_slot;
static DYNAMIC_STRING ds_connection_name; static DYNAMIC_STRING ds_connection_name;
...@@ -6049,6 +6050,11 @@ void do_connect(struct st_command *command) ...@@ -6049,6 +6050,11 @@ void do_connect(struct st_command *command)
{ {
connect_timeout= atoi(con_options + sizeof("connect_timeout=")-1); connect_timeout= atoi(con_options + sizeof("connect_timeout=")-1);
} }
else if (strncasecmp(con_options, "CHARSET=",
sizeof("CHARSET=") - 1) == 0)
{
csname= strdup(con_options + sizeof("CHARSET=") - 1);
}
else else
die("Illegal option to connect: %.*s", die("Illegal option to connect: %.*s",
(int) (end - con_options), con_options); (int) (end - con_options), con_options);
...@@ -6086,7 +6092,7 @@ void do_connect(struct st_command *command) ...@@ -6086,7 +6092,7 @@ void do_connect(struct st_command *command)
mysql_options(con_slot->mysql, MYSQL_OPT_COMPRESS, NullS); mysql_options(con_slot->mysql, MYSQL_OPT_COMPRESS, NullS);
mysql_options(con_slot->mysql, MYSQL_OPT_LOCAL_INFILE, 0); mysql_options(con_slot->mysql, MYSQL_OPT_LOCAL_INFILE, 0);
mysql_options(con_slot->mysql, MYSQL_SET_CHARSET_NAME, mysql_options(con_slot->mysql, MYSQL_SET_CHARSET_NAME,
charset_info->csname); csname?csname: charset_info->csname);
if (opt_charsets_dir) if (opt_charsets_dir)
mysql_options(con_slot->mysql, MYSQL_SET_CHARSET_DIR, mysql_options(con_slot->mysql, MYSQL_SET_CHARSET_DIR,
opt_charsets_dir); opt_charsets_dir);
...@@ -6197,6 +6203,7 @@ void do_connect(struct st_command *command) ...@@ -6197,6 +6203,7 @@ void do_connect(struct st_command *command)
#ifdef HAVE_SMEM #ifdef HAVE_SMEM
dynstr_free(&ds_shm); dynstr_free(&ds_shm);
#endif #endif
free(csname);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -5,3 +5,23 @@ Com_select 10 ...@@ -5,3 +5,23 @@ Com_select 10
SHOW local STATUS LIKE 'com_select'; SHOW local STATUS LIKE 'com_select';
Variable_name Value Variable_name Value
Com_select 0 Com_select 0
# Test if charset changes after reset (utf8)
connect utf8_conn,localhost,root,,,,,CHARSET=utf8;
connection utf8_conn;
SELECT IF(@@character_set_client='utf8','OK', 'FAIL') AS RESULT;
RESULT
OK
SELECT IF(@@character_set_client='utf8','OK', 'FAIL') AS RESULT;
RESULT
OK
disconnect utf8_conn;
# Test if charset changes after reset (latin1)
connect latin1_conn,localhost,root,,,,,CHARSET=latin1;
connection latin1_conn;
SELECT IF(@@character_set_client='latin1','OK', 'FAIL') AS RESULT;
RESULT
OK
SELECT IF(@@character_set_client='latin1','OK', 'FAIL') AS RESULT;
RESULT
OK
disconnect latin1_conn;
...@@ -23,3 +23,18 @@ SHOW local STATUS LIKE 'com_select'; ...@@ -23,3 +23,18 @@ SHOW local STATUS LIKE 'com_select';
SHOW local STATUS LIKE 'com_select'; SHOW local STATUS LIKE 'com_select';
--echo # Test if charset changes after reset (utf8)
connect(utf8_conn,localhost,root,,,,,CHARSET=utf8);
connection utf8_conn;
SELECT IF(@@character_set_client='utf8','OK', 'FAIL') AS RESULT;
--reset_connection
SELECT IF(@@character_set_client='utf8','OK', 'FAIL') AS RESULT;
disconnect utf8_conn;
--echo # Test if charset changes after reset (latin1)
connect(latin1_conn,localhost,root,,,,,CHARSET=latin1);
connection latin1_conn;
SELECT IF(@@character_set_client='latin1','OK', 'FAIL') AS RESULT;
--reset_connection
SELECT IF(@@character_set_client='latin1','OK', 'FAIL') AS RESULT;
disconnect latin1_conn;
\ No newline at end of file
...@@ -840,6 +840,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) ...@@ -840,6 +840,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
prepare_derived_at_open= FALSE; prepare_derived_at_open= FALSE;
create_tmp_table_for_derived= FALSE; create_tmp_table_for_derived= FALSE;
save_prep_leaf_list= FALSE; save_prep_leaf_list= FALSE;
org_charset= 0;
/* Restore THR_THD */ /* Restore THR_THD */
set_current_thd(old_THR_THD); set_current_thd(old_THR_THD);
inc_thread_count(); inc_thread_count();
......
...@@ -2312,6 +2312,9 @@ class THD :public Statement, ...@@ -2312,6 +2312,9 @@ class THD :public Statement,
uint dbug_sentry; // watch out for memory corruption uint dbug_sentry; // watch out for memory corruption
#endif #endif
struct st_my_thread_var *mysys_var; struct st_my_thread_var *mysys_var;
/* Original charset number from the first client packet, or COM_CHANGE_USER*/
CHARSET_INFO *org_charset;
private: private:
/* /*
Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
......
...@@ -793,6 +793,7 @@ bool thd_init_client_charset(THD *thd, uint cs_number) ...@@ -793,6 +793,7 @@ bool thd_init_client_charset(THD *thd, uint cs_number)
cs->csname); cs->csname);
return true; return true;
} }
thd->org_charset= cs;
thd->update_charset(cs,cs,cs); thd->update_charset(cs,cs,cs);
} }
return false; return false;
......
...@@ -1689,6 +1689,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1689,6 +1689,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->status_var.com_other++; thd->status_var.com_other++;
thd->change_user(); thd->change_user();
thd->clear_error(); // if errors from rollback thd->clear_error(); // if errors from rollback
/* Restore original charset from client authentication packet.*/
if(thd->org_charset)
thd->update_charset(thd->org_charset,thd->org_charset,thd->org_charset);
my_ok(thd, 0, 0, 0); my_ok(thd, 0, 0, 0);
break; break;
} }
......
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