You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-08 14:02:17 +03:00
Fix for CONC-332:
After calling mysql_real_connect or mysql_change_user the server_status was not updated, since run_plugin_auth didn't read the entire OK packet.
This commit is contained in:
@@ -1967,21 +1967,7 @@ mysql_send_query(MYSQL* mysql, const char* query, unsigned long length)
|
|||||||
return ma_simple_command(mysql, COM_QUERY, query, length, 1,0);
|
return ma_simple_command(mysql, COM_QUERY, query, length, 1,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mthd_my_read_query_result(MYSQL *mysql)
|
int ma_read_ok_packet(MYSQL *mysql, uchar *pos, ulong length)
|
||||||
{
|
|
||||||
uchar *pos;
|
|
||||||
ulong field_count;
|
|
||||||
MYSQL_DATA *fields;
|
|
||||||
ulong length;
|
|
||||||
|
|
||||||
if (!mysql || (length = ma_net_safe_read(mysql)) == packet_error)
|
|
||||||
{
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
free_old_query(mysql); /* Free old result */
|
|
||||||
get_info:
|
|
||||||
pos=(uchar*) mysql->net.read_pos;
|
|
||||||
if ((field_count= net_field_length(&pos)) == 0)
|
|
||||||
{
|
{
|
||||||
size_t item_len;
|
size_t item_len;
|
||||||
mysql->affected_rows= net_field_length_ll(&pos);
|
mysql->affected_rows= net_field_length_ll(&pos);
|
||||||
@@ -2106,6 +2092,23 @@ get_info:
|
|||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mthd_my_read_query_result(MYSQL *mysql)
|
||||||
|
{
|
||||||
|
uchar *pos;
|
||||||
|
ulong field_count;
|
||||||
|
MYSQL_DATA *fields;
|
||||||
|
ulong length;
|
||||||
|
|
||||||
|
if (!mysql || (length = ma_net_safe_read(mysql)) == packet_error)
|
||||||
|
{
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
free_old_query(mysql); /* Free old result */
|
||||||
|
get_info:
|
||||||
|
pos=(uchar*) mysql->net.read_pos;
|
||||||
|
if ((field_count= net_field_length(&pos)) == 0)
|
||||||
|
return ma_read_ok_packet(mysql, pos, length);
|
||||||
if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
|
if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
|
||||||
{
|
{
|
||||||
int error=mysql_handle_local_infile(mysql, (char *)pos);
|
int error=mysql_handle_local_infile(mysql, (char *)pos);
|
||||||
|
@@ -10,6 +10,7 @@ static int client_mpvio_write_packet(struct st_plugin_vio*, const uchar*, size_t
|
|||||||
static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||||
extern void read_user_name(char *name);
|
extern void read_user_name(char *name);
|
||||||
extern char *ma_send_connect_attr(MYSQL *mysql, unsigned char *buffer);
|
extern char *ma_send_connect_attr(MYSQL *mysql, unsigned char *buffer);
|
||||||
|
extern int ma_read_ok_packet(MYSQL *mysql, uchar *pos, ulong length);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int (*read_packet)(struct st_plugin_vio *vio, uchar **buf);
|
int (*read_packet)(struct st_plugin_vio *vio, uchar **buf);
|
||||||
@@ -577,7 +578,6 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
|
|||||||
errno);
|
errno);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mysql->net.read_pos[0] == 254)
|
if (mysql->net.read_pos[0] == 254)
|
||||||
{
|
{
|
||||||
/* The server asked to use a different authentication plugin */
|
/* The server asked to use a different authentication plugin */
|
||||||
@@ -632,6 +632,8 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
|
|||||||
net->read_pos[0] should always be 0 here if the server implements
|
net->read_pos[0] should always be 0 here if the server implements
|
||||||
the protocol correctly
|
the protocol correctly
|
||||||
*/
|
*/
|
||||||
return mysql->net.read_pos[0] != 0;
|
if (mysql->net.read_pos[0] == 0)
|
||||||
|
return ma_read_ok_packet(mysql, mysql->net.read_pos + 1, pkt_length);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1486,7 +1486,45 @@ static int test_conc327(MYSQL *unused __attribute__((unused)))
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int test_conc332(MYSQL *unused __attribute__((unused)))
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
MYSQL *mysql= mysql_init(NULL);
|
||||||
|
int server_status1, server_status2;
|
||||||
|
|
||||||
|
my_test_connect(mysql, hostname, username, password, schema,
|
||||||
|
port, socketname, 0);
|
||||||
|
|
||||||
|
FAIL_IF(mysql_errno(mysql), "Error during connect");
|
||||||
|
|
||||||
|
mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status1);
|
||||||
|
diag("server_status: %d", server_status1);
|
||||||
|
|
||||||
|
if (server_status1 & SERVER_STATUS_AUTOCOMMIT)
|
||||||
|
rc= mysql_query(mysql, "SET autocommit= 0");
|
||||||
|
else
|
||||||
|
rc= mysql_query(mysql, "SET autocommit= 1");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status2);
|
||||||
|
diag("server_status after changing autocommit: %d", server_status2);
|
||||||
|
|
||||||
|
rc= mysql_change_user(mysql, username, password, schema);
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
|
||||||
|
mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status2);
|
||||||
|
diag("server_status after mysql_change_user: %d", server_status2);
|
||||||
|
if (server_status1 != server_status2)
|
||||||
|
{
|
||||||
|
diag("Expected server_status %d instead of %d", server_status1, server_status2);
|
||||||
|
mysql_close(mysql);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
mysql_close(mysql);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
struct my_tests_st my_tests[] = {
|
struct my_tests_st my_tests[] = {
|
||||||
|
{"test_conc332", test_conc332, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
{"test_conc327", test_conc327, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_conc327", test_conc327, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_conc317", test_conc317, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_conc317", test_conc317, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
|
Reference in New Issue
Block a user