mirror of https://github.com/sysown/proxysql
Apply patches to mariadb_connector_c_3.0.2 #1126
parent
5edbf2c2ba
commit
69596e230a
@ -0,0 +1,9 @@
|
||||
@@ -85,7 +85,7 @@
|
||||
if (! next)
|
||||
{ /* Time to alloc new block */
|
||||
get_size= MAX(Size+ALIGN_SIZE(sizeof(MA_USED_MEM)),
|
||||
- (mem_root->block_size & ~1) * (mem_root->block_num >> 2));
|
||||
+ (mem_root->block_size & ~1) * ( (mem_root->block_num >> 2) > 4 ? 4 : (mem_root->block_num >> 2) ) );
|
||||
|
||||
if (!(next = (MA_USED_MEM*) malloc(get_size)))
|
||||
{
|
||||
@ -0,0 +1,8 @@
|
||||
@@ -732,6 +732,7 @@
|
||||
{ 247, 1, UTF8_MB4, UTF8_MB4"_vietnamese_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid},
|
||||
|
||||
{ 254, 1, UTF8_MB3, UTF8_MB3"_general_cs", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid},
|
||||
+ { 255, 1, UTF8_MB4, UTF8_MB4"_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid},
|
||||
{ 576, 1, UTF8_MB3, UTF8_MB3"_croatian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/
|
||||
{ 577, 1, UTF8_MB3, UTF8_MB3"_myanmar_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/
|
||||
{ 578, 1, UTF8_MB3, UTF8_MB3"_thai_520_w2", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/
|
||||
@ -0,0 +1,56 @@
|
||||
@@ -105,6 +105,35 @@
|
||||
}
|
||||
}
|
||||
|
||||
+unsigned char decode_char(char x) {
|
||||
+ if (x >= '0' && x <= '9')
|
||||
+ return (x - 0x30);
|
||||
+ else if (x >= 'A' && x <= 'F')
|
||||
+ return(x - 0x37);
|
||||
+ else if (x >= 'a' && x <= 'f')
|
||||
+ return(x - 0x57);
|
||||
+ else {
|
||||
+ fprintf(stderr,"%s:%d:%s(): [ERROR in libmariadbclient]: \n", __FILE__, __LINE__, __func__);
|
||||
+ return 0;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void unhex_pass(unsigned char *out, const char *in) {
|
||||
+ int i=0;
|
||||
+ for (i=0;i<SHA1_MAX_LENGTH;i++) {
|
||||
+ // this can be simplified a lot, but leaving like this to make it easy to debug
|
||||
+ unsigned char c=0, d=0;
|
||||
+ c=decode_char(in[i*2]);
|
||||
+ c=(c*16) & 0xF0;
|
||||
+ d=decode_char(in[i*2+1]);
|
||||
+ d=d & 0x0F;
|
||||
+ c+=d;
|
||||
+ out[i]=c;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+
|
||||
+
|
||||
void ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password)
|
||||
{
|
||||
_MA_SHA1_CTX context;
|
||||
@@ -112,10 +141,15 @@
|
||||
unsigned char sha2[SHA1_MAX_LENGTH];
|
||||
|
||||
|
||||
- /* Phase 1: hash password */
|
||||
- ma_SHA1Init(&context);
|
||||
- ma_SHA1Update(&context, (unsigned char *)password, strlen((char *)password));
|
||||
- ma_SHA1Final(sha1, &context);
|
||||
+ if (password[0]=='*') {
|
||||
+ unhex_pass(sha1,password+1);
|
||||
+ } else {
|
||||
+ /* Phase 1: hash password */
|
||||
+ ma_SHA1Init(&context);
|
||||
+ ma_SHA1Update(&context, (unsigned char *)password, strlen((char *)password));
|
||||
+ ma_SHA1Final(sha1, &context);
|
||||
+ }
|
||||
+
|
||||
|
||||
/* Phase 2: hash sha1 */
|
||||
ma_SHA1Init(&context);
|
||||
@ -0,0 +1,31 @@
|
||||
@@ -479,19 +479,20 @@
|
||||
struct mysql_set_character_set_params {
|
||||
MYSQL *mysql;
|
||||
const char *csname;
|
||||
+ uint charsetnr;
|
||||
};
|
||||
static void
|
||||
mysql_set_character_set_start_internal(void *d)
|
||||
{
|
||||
MK_ASYNC_INTERNAL_BODY(
|
||||
mysql_set_character_set,
|
||||
- (parms->mysql, parms->csname),
|
||||
+ (parms->mysql, parms->csname, parms->charsetnr),
|
||||
parms->mysql,
|
||||
int,
|
||||
r_int)
|
||||
}
|
||||
int STDCALL
|
||||
-mysql_set_character_set_start(int *ret, MYSQL *mysql, const char *csname)
|
||||
+mysql_set_character_set_start(int *ret, MYSQL *mysql, const char *csname, uint charsetnr)
|
||||
{
|
||||
MK_ASYNC_START_BODY(
|
||||
mysql_set_character_set,
|
||||
@@ -500,6 +501,7 @@
|
||||
WIN_SET_NONBLOCKING(mysql)
|
||||
parms.mysql= mysql;
|
||||
parms.csname= csname;
|
||||
+ parms.charsetnr= charsetnr;
|
||||
},
|
||||
1,
|
||||
r_int,
|
||||
@ -0,0 +1,110 @@
|
||||
@@ -1494,9 +1494,16 @@
|
||||
|
||||
mysql->client_flag= client_flag;
|
||||
|
||||
+ {
|
||||
+ volatile my_bool net_blocking = ma_pvio_is_blocking(net->pvio);
|
||||
+ if (!net_blocking)
|
||||
+ ma_pvio_blocking(net->pvio, TRUE, 0);
|
||||
if (run_plugin_auth(mysql, scramble_data, scramble_len,
|
||||
scramble_plugin, db))
|
||||
goto error;
|
||||
+ if (!net_blocking)
|
||||
+ ma_pvio_blocking(net->pvio, FALSE, 0);
|
||||
+ }
|
||||
|
||||
if (mysql->client_flag & CLIENT_COMPRESS)
|
||||
net->compress= 1;
|
||||
@@ -1625,7 +1632,7 @@
|
||||
if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
|
||||
mysql->db, mysql->port, mysql->unix_socket,
|
||||
mysql->client_flag | CLIENT_REMEMBER_OPTIONS) ||
|
||||
- mysql_set_character_set(&tmp_mysql, mysql->charset->csname))
|
||||
+ mysql_set_character_set(&tmp_mysql, mysql->charset->csname, NULL))
|
||||
{
|
||||
if (ctxt)
|
||||
my_context_install_suspend_resume_hook(ctxt, NULL, NULL);
|
||||
@@ -1671,6 +1678,7 @@
|
||||
{
|
||||
if (mysql->stmts)
|
||||
{
|
||||
+/*
|
||||
LIST *li_stmt= mysql->stmts;
|
||||
|
||||
for (; li_stmt; li_stmt= li_stmt->next)
|
||||
@@ -1679,6 +1687,7 @@
|
||||
stmt->mysql= NULL;
|
||||
SET_CLIENT_STMT_ERROR(stmt, CR_STMT_CLOSED, SQLSTATE_UNKNOWN, function_name);
|
||||
}
|
||||
+*/
|
||||
mysql->stmts= NULL;
|
||||
}
|
||||
}
|
||||
@@ -1948,6 +1957,33 @@
|
||||
return;
|
||||
}
|
||||
|
||||
+void STDCALL
|
||||
+mysql_close_no_command(MYSQL *mysql)
|
||||
+{
|
||||
+ if (mysql) /* Some simple safety */
|
||||
+ {
|
||||
+
|
||||
+ if (mysql->methods) {
|
||||
+ if (mysql->net.pvio) {
|
||||
+ free_old_query(mysql);
|
||||
+ mysql->status=MYSQL_STATUS_READY; /* Force command */
|
||||
+ mysql->options.reconnect=0;
|
||||
+ end_server(mysql);
|
||||
+ }
|
||||
+ }
|
||||
+ mysql_close_memory(mysql);
|
||||
+ mysql_close_options(mysql);
|
||||
+ mysql->host_info=mysql->user=mysql->passwd=mysql->db=0;
|
||||
+
|
||||
+ /* Clear pointers for better safety */
|
||||
+ bzero((char*) &mysql->options,sizeof(mysql->options));
|
||||
+ mysql->net.pvio= 0;
|
||||
+ if (mysql->free_me)
|
||||
+ free(mysql);
|
||||
+ }
|
||||
+ return;
|
||||
+}
|
||||
+
|
||||
|
||||
/**************************************************************************
|
||||
** Do a query. If query returned rows, free old rows.
|
||||
@@ -3425,18 +3461,27 @@
|
||||
mariadb_get_charset_info(mysql, cs);
|
||||
}
|
||||
|
||||
-int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname)
|
||||
+int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname, uint charsetnr)
|
||||
{
|
||||
const MARIADB_CHARSET_INFO *cs;
|
||||
|
||||
- if (!csname)
|
||||
+ if (!csname && !charsetnr)
|
||||
goto error;
|
||||
|
||||
- if ((cs= mysql_find_charset_name(csname)))
|
||||
- {
|
||||
- char buff[64];
|
||||
+ if (csname) {
|
||||
+ cs = mysql_find_charset_name(csname);
|
||||
+ } else {
|
||||
+ cs = mysql_find_charset_nr(charsetnr);
|
||||
+ }
|
||||
+ if (cs)
|
||||
+ {
|
||||
+ char buff[128];
|
||||
+ if (csname) { // default behavior
|
||||
+ snprintf(buff, 63, "SET NAMES %s", cs->csname);
|
||||
+ } else {
|
||||
+ snprintf(buff, 63, "SET NAMES %s COLLATE %s", cs->csname, cs->name);
|
||||
+ }
|
||||
|
||||
- snprintf(buff, 63, "SET NAMES %s", cs->csname);
|
||||
if (!mysql_real_query(mysql, buff, (unsigned long)strlen(buff)))
|
||||
{
|
||||
mysql->charset= cs;
|
||||
@ -0,0 +1,11 @@
|
||||
--- /tmp/basic-t.c 2017-12-28 14:55:55.958512116 +0100
|
||||
+++ unittest/libmariadb/basic-t.c 2017-12-28 14:56:08.770490417 +0100
|
||||
@@ -48,7 +48,7 @@
|
||||
rc= mysql_query(mysql, "CREATE TABLE a (a varchar(200))");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
- rc= mysql_set_character_set(mysql, "utf8");
|
||||
+ rc= mysql_set_character_set(mysql, "utf8", 0);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
for (i=0; i < 10; i++)
|
||||
@ -0,0 +1,71 @@
|
||||
--- /tmp/charset.c 2017-12-28 14:58:14.174281738 +0100
|
||||
+++ unittest/libmariadb/charset.c 2017-12-28 14:59:53.510120540 +0100
|
||||
@@ -74,12 +74,12 @@
|
||||
char *csname= (char*) "utf8";
|
||||
char *csdefault= (char*)mysql_character_set_name(mysql);
|
||||
|
||||
- FAIL_IF(mysql_set_character_set(mysql, csname), mysql_error(mysql));
|
||||
+ FAIL_IF(mysql_set_character_set(mysql, csname, 0), mysql_error(mysql));
|
||||
|
||||
mysql_get_character_set_info(mysql, &cs);
|
||||
|
||||
FAIL_IF(strcmp(cs.csname, "utf8") || strcmp(cs.name, "utf8_general_ci"), "Character set != UTF8");
|
||||
- FAIL_IF(mysql_set_character_set(mysql, csdefault), mysql_error(mysql));
|
||||
+ FAIL_IF(mysql_set_character_set(mysql, csdefault, 0), mysql_error(mysql));
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -542,7 +542,7 @@
|
||||
}
|
||||
/* Retrieve character set information. */
|
||||
|
||||
- mysql_set_character_set(mysql, "latin1");
|
||||
+ mysql_set_character_set(mysql, "latin1", 0);
|
||||
bug30472_retrieve_charset_info(mysql,
|
||||
character_set_name_1,
|
||||
character_set_client_1,
|
||||
@@ -551,7 +551,7 @@
|
||||
|
||||
/* Switch client character set. */
|
||||
|
||||
- FAIL_IF(mysql_set_character_set(mysql, "utf8"), "Setting cs to utf8 failed");
|
||||
+ FAIL_IF(mysql_set_character_set(mysql, "utf8", 0), "Setting cs to utf8 failed");
|
||||
|
||||
/* Retrieve character set information. */
|
||||
|
||||
@@ -581,7 +581,7 @@
|
||||
/* Call mysql_change_user() with the same username, password, database. */
|
||||
|
||||
rc= mysql_change_user(mysql, username, password, (schema) ? schema : "test");
|
||||
- mysql_set_character_set(mysql, "latin1");
|
||||
+ mysql_set_character_set(mysql, "latin1", 0);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
/* Retrieve character set information. */
|
||||
@@ -647,7 +647,7 @@
|
||||
/* ignore ucs2 */
|
||||
if (strcmp(row[0], "ucs2") && strcmp(row[0], "utf16le") && strcmp(row[0], "utf8mb4") &&
|
||||
strcmp(row[0], "utf16") && strcmp(row[0], "utf32")) {
|
||||
- rc= mysql_set_character_set(mysql, row[0]);
|
||||
+ rc= mysql_set_character_set(mysql, row[0], 0);
|
||||
check_mysql_rc(rc, mysql);
|
||||
}
|
||||
}
|
||||
@@ -748,7 +748,7 @@
|
||||
|
||||
if (strcmp(osname, "utf8"))
|
||||
{
|
||||
- rc= mysql_set_character_set(mysql, "utf8");
|
||||
+ rc= mysql_set_character_set(mysql, "utf8", 0);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
csname2= mysql_character_set_name(mysql);
|
||||
@@ -756,7 +756,7 @@
|
||||
|
||||
FAIL_IF(!strcmp(csname2, csname1), "Wrong charset: expected utf8");
|
||||
|
||||
- rc= mysql_set_character_set(mysql, "auto");
|
||||
+ rc= mysql_set_character_set(mysql, "auto", 0);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
csname2= mysql_character_set_name(mysql);
|
||||
Loading…
Reference in new issue