You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-07 02:42:49 +03:00
Post-fix after ba9f5f4af1
(adding _server_host
attribute). mysql->host is not always set (apparently not when reconnecting), This made MariaDB C/C produce invalid handshake reply packet with incorrecly encoded connection attributes. there cannot be connection attributes with empty values in MySQL protocol. Fix connector to only send _server_host is host is valid non-empty string. Also prevent adding connection attributes with empty values.
This commit is contained in:
@@ -1080,7 +1080,7 @@ char *ma_send_connect_attr(MYSQL *mysql, unsigned char *buffer)
|
|||||||
|
|
||||||
/** set some default attributes */
|
/** set some default attributes */
|
||||||
static my_bool
|
static my_bool
|
||||||
ma_set_connect_attrs(MYSQL *mysql)
|
ma_set_connect_attrs(MYSQL *mysql, const char *host)
|
||||||
{
|
{
|
||||||
char buffer[255];
|
char buffer[255];
|
||||||
int rc= 0;
|
int rc= 0;
|
||||||
@@ -1097,8 +1097,10 @@ ma_set_connect_attrs(MYSQL *mysql)
|
|||||||
|
|
||||||
rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_client_name", "libmariadb")
|
rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_client_name", "libmariadb")
|
||||||
+ mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_client_version", MARIADB_PACKAGE_VERSION)
|
+ mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_client_version", MARIADB_PACKAGE_VERSION)
|
||||||
+ mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_os", MARIADB_SYSTEM_TYPE)
|
+ mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_os", MARIADB_SYSTEM_TYPE);
|
||||||
+ mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_server_host", mysql->host);
|
|
||||||
|
if (host && *host)
|
||||||
|
rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_server_host", host);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
snprintf(buffer, 255, "%lu", (ulong) GetCurrentThreadId());
|
snprintf(buffer, 255, "%lu", (ulong) GetCurrentThreadId());
|
||||||
@@ -1193,7 +1195,10 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
|
|||||||
if (!mysql->methods)
|
if (!mysql->methods)
|
||||||
mysql->methods= &MARIADB_DEFAULT_METHODS;
|
mysql->methods= &MARIADB_DEFAULT_METHODS;
|
||||||
|
|
||||||
ma_set_connect_attrs(mysql);
|
if (!host || !host[0])
|
||||||
|
host = mysql->options.host;
|
||||||
|
|
||||||
|
ma_set_connect_attrs(mysql, host);
|
||||||
|
|
||||||
if (net->pvio) /* check if we are already connected */
|
if (net->pvio) /* check if we are already connected */
|
||||||
{
|
{
|
||||||
@@ -1222,8 +1227,6 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Some empty-string-tests are done because of ODBC */
|
/* Some empty-string-tests are done because of ODBC */
|
||||||
if (!host || !host[0])
|
|
||||||
host=mysql->options.host;
|
|
||||||
if (!user || !user[0])
|
if (!user || !user[0])
|
||||||
user=mysql->options.user;
|
user=mysql->options.user;
|
||||||
if (!passwd)
|
if (!passwd)
|
||||||
@@ -2897,6 +2900,11 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...)
|
|||||||
void *arg2= va_arg(ap, void *);
|
void *arg2= va_arg(ap, void *);
|
||||||
size_t key_len= arg1 ? strlen((char *)arg1) : 0,
|
size_t key_len= arg1 ? strlen((char *)arg1) : 0,
|
||||||
value_len= arg2 ? strlen((char *)arg2) : 0;
|
value_len= arg2 ? strlen((char *)arg2) : 0;
|
||||||
|
if (!key_len || !value_len)
|
||||||
|
{
|
||||||
|
SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
size_t storage_len= key_len + value_len +
|
size_t storage_len= key_len + value_len +
|
||||||
get_store_length(key_len) +
|
get_store_length(key_len) +
|
||||||
get_store_length(value_len);
|
get_store_length(value_len);
|
||||||
|
Reference in New Issue
Block a user