Skip to content

Commit 6f06e96

Browse files
V S Murthy Sidagamtanydixi
authored andcommitted
Bug#35054579 Issue in Oracle MySQL Client using utf16 charset
Back porting the bug to 5.7 branch. Change-Id: I06810ab5d85ac6f65b94ff1d12bc116cf40d7fa1
1 parent 2eee58b commit 6f06e96

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

client/mysql.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static int com_nopager(String *str, char*), com_pager(String *str, char*),
290290
#endif
291291

292292
static int read_and_execute(bool interactive);
293-
static void init_connection_options(MYSQL *mysql);
293+
static bool init_connection_options(MYSQL *mysql);
294294
static int sql_connect(char *host,char *database,char *user,char *password,
295295
uint silent);
296296
static const char *server_version_string(MYSQL *mysql);
@@ -5015,7 +5015,12 @@ sql_real_connect(char *host,char *database,char *user,char *password,
50155015
}
50165016

50175017
mysql_init(&mysql);
5018-
init_connection_options(&mysql);
5018+
if (init_connection_options(&mysql))
5019+
{
5020+
(void) put_error(&mysql);
5021+
(void) fflush(stdout);
5022+
return ignore_errors ? -1 : 1; // Abort
5023+
}
50195024

50205025
#ifdef _WIN32
50215026
uint cnv_errors;
@@ -5108,7 +5113,7 @@ sql_real_connect(char *host,char *database,char *user,char *password,
51085113

51095114

51105115
/* Initialize options for the given connection handle. */
5111-
static void
5116+
static bool
51125117
init_connection_options(MYSQL *mysql)
51135118
{
51145119
my_bool handle_expired= (opt_connect_expired_password || !status.batch) ?
@@ -5151,7 +5156,7 @@ init_connection_options(MYSQL *mysql)
51515156
mysql_options(mysql, MYSQL_INIT_COMMAND, init_command);
51525157
}
51535158

5154-
mysql_set_character_set(mysql, default_charset);
5159+
if (mysql_set_character_set(mysql, default_charset)) return true;
51555160

51565161
if (opt_plugin_dir && *opt_plugin_dir)
51575162
mysql_options(mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir);
@@ -5170,6 +5175,7 @@ init_connection_options(MYSQL *mysql)
51705175
mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "program_name", "mysql");
51715176

51725177
mysql_options(mysql, MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, &handle_expired);
5178+
return false;
51735179
}
51745180

51755181

include/errmsg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ extern const char *client_errors[]; /* Error messages */
115115
#define CR_DUPLICATE_CONNECTION_ATTR 2060
116116
#define CR_AUTH_PLUGIN_ERR 2061
117117
#define CR_INSECURE_API_ERR 2062
118-
#define CR_ERROR_LAST /*Copy last error nr:*/ 2062
118+
#define CR_INVALID_CLIENT_CHARSET 2063
119+
#define CR_ERROR_LAST /*Copy last error nr:*/ 2063
119120
/* Add error numbers before CR_ERROR_LAST and change it accordingly. */
120121

121122
#endif /* ERRMSG_INCLUDED */

libmysql/errmsg.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ const char *client_errors[]=
9797
"There is an attribute with the same name already",
9898
"Authentication plugin '%s' reported error: %s",
9999
"Insecure API function call: '%s' Use instead: '%s'",
100+
"'%-.32s' character set is having more than 1 byte minimum character "
101+
"length, which cannot be used as a client character set. Please use any "
102+
"of the single byte minimum ones, e.g. utf8mb4, latin1 etc.",
100103
""
101104
};
102105

sql-common/client.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5953,6 +5953,11 @@ ulong STDCALL mysql_get_server_version(MYSQL *mysql) {
59535953
return major * 10000 + minor * 100 + version;
59545954
}
59555955

5956+
#ifndef MYSQL_SERVER
5957+
static my_bool is_supported_parser_charset(const CHARSET_INFO *cs) {
5958+
return (cs->mbminlen == 1);
5959+
}
5960+
#endif
59565961
/*
59575962
mysql_set_character_set function sends SET NAMES cs_name to
59585963
the server (which changes character_set_client, character_set_result
@@ -5979,6 +5984,17 @@ int STDCALL mysql_set_character_set(MYSQL *mysql, const char *cs_name) {
59795984
cs_name = mysql->options.charset_name;
59805985
}
59815986

5987+
#ifndef MYSQL_SERVER
5988+
if (mysql->charset != NULL) {
5989+
if (!is_supported_parser_charset(mysql->charset)) {
5990+
set_mysql_extended_error(mysql, CR_INVALID_CLIENT_CHARSET,
5991+
unknown_sqlstate,
5992+
ER(CR_INVALID_CLIENT_CHARSET), cs_name);
5993+
return 1;
5994+
}
5995+
}
5996+
#endif
5997+
59825998
if (strlen(cs_name) < MY_CS_NAME_SIZE &&
59835999
(cs = get_charset_by_csname(cs_name, MY_CS_PRIMARY, MYF(0)))) {
59846000
char buff[MY_CS_NAME_SIZE + 10];

0 commit comments

Comments
 (0)