1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

Merge branch '3.1' into 3.3

This commit is contained in:
Georg Richter
2022-07-24 10:52:52 +02:00
9 changed files with 37 additions and 29 deletions

View File

@@ -105,7 +105,12 @@ extern const char *mariadb_client_errors[]; /* Error messages */
#define CR_PLUGIN_NOT_ALLOWED 5010
#define CR_CONNSTR_PARSE_ERROR 5011
#define CR_ERR_LOAD_PLUGIN 5012
#define CR_ERR_NET_READ 5013
#define CR_ERR_NET_WRITE 5014
#define CR_ERR_NET_UNCOMPRESS 5015
/* Always last, if you add new error codes please update the
value for CR_MARIADB_LAST_ERROR */
#define CR_MARIADB_LAST_ERROR CR_ERR_LOAD_PLUGIN
#define CR_MARIADB_LAST_ERROR CR_ERR_NET_UNCOMPRESS
#endif

View File

@@ -33,6 +33,7 @@
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
#define strerror_r(errno,buf,len) strerror_s(buf,len,errno)
#endif
#define STDCALL __stdcall
#endif

View File

@@ -107,6 +107,9 @@ const char *mariadb_client_errors[] =
/* 5010 */ "Authentication plugin '%s' couldn't be found in restricted_auth plugin list.",
/* 5011 */ "Parse error in connection string (offset %d)",
/* 5012 */ "Error while loading plugin '%s'",
/* 5013 */ "Read error: %s (%d)",
/* 5014 */ "Write error: %s (%d)",
/* 5015 */ "Error while uncompressing packet",
""
};

View File

@@ -29,7 +29,7 @@
#include <ma_sys.h>
#include <ma_string.h>
#include "mysql.h"
#include "ma_server_error.h"
#include "errmsg.h"
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
@@ -125,7 +125,7 @@ static my_bool net_realloc(NET *net, size_t length)
if (length >= net->max_packet_size)
{
net->error=1;
net->last_errno=ER_NET_PACKET_TOO_LARGE;
net->pvio->set_error(net->pvio->mysql, CR_NET_PACKET_TOO_LARGE, SQLSTATE_UNKNOWN, 0);
return(1);
}
pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
@@ -313,7 +313,7 @@ int ma_net_real_write(NET *net, const char *packet, size_t len)
uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
if (!(b=(uchar*) malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1)))
{
net->last_errno=ER_OUT_OF_RESOURCES;
net->pvio->set_error(net->pvio->mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
net->error=2;
net->reading_or_writing=0;
return(1);
@@ -337,8 +337,13 @@ int ma_net_real_write(NET *net, const char *packet, size_t len)
{
if ((length=ma_pvio_write(net->pvio,(uchar *)pos,(size_t) (end-pos))) <= 0)
{
int save_errno= errno;
char errmsg[100];
net->error=2; /* Close socket */
net->last_errno= ER_NET_ERROR_ON_WRITE;
strerror_r(save_errno, errmsg, 100);
net->pvio->set_error(net->pvio->mysql, CR_ERR_NET_WRITE, SQLSTATE_UNKNOWN, 0,
errmsg, save_errno);
net->reading_or_writing=0;
#ifdef HAVE_COMPRESS
if (net->compress)
@@ -557,8 +562,7 @@ ulong ma_net_read(NET *net)
if (_mariadb_uncompress(net, (unsigned char*) net->buff + net->where_b, &packet_length, &complen))
{
net->error=2; /* caller will close socket */
net->last_errno=ER_NET_UNCOMPRESS_ERROR;
break;
net->pvio->set_error(net->pvio->mysql, CR_ERR_NET_UNCOMPRESS, SQLSTATE_UNKNOWN, 0);
return packet_error;
}
buffer_length+= complen;

View File

@@ -232,6 +232,6 @@ end:
void ma_pvio_tls_set_connection(MYSQL *mysql)
{
return ma_tls_set_connection(mysql);
ma_tls_set_connection(mysql);
}
#endif /* HAVE_TLS */

View File

@@ -1767,7 +1767,8 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned lon
goto fail;
if (!is_multi && mysql->net.extension->multi_status == COM_MULTI_ENABLED)
ma_multi_command(mysql, COM_MULTI_END);
if (ma_multi_command(mysql, COM_MULTI_END))
goto fail;
if (mysql->net.extension->multi_status > COM_MULTI_OFF ||
mysql->options.extension->skip_read_response)

View File

@@ -878,12 +878,7 @@ static void ma_tls_set_error(MYSQL *mysql, void *ssl, int ssl_errno)
char ssl_error[MAX_SSL_ERR_LEN];
const char *ssl_error_reason;
MARIADB_PVIO *pvio= mysql->net.pvio;
if (!ssl_errno)
{
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, "Unknown SSL error");
return;
}
int save_errno= errno;
/* give a more descriptive error message for alerts */
if (ssl_errno == GNUTLS_E_FATAL_ALERT_RECEIVED)
@@ -898,15 +893,16 @@ static void ma_tls_set_error(MYSQL *mysql, void *ssl, int ssl_errno)
return;
}
if ((ssl_error_reason= gnutls_strerror(ssl_errno)))
if (ssl_errno && (ssl_error_reason= gnutls_strerror(ssl_errno)))
{
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0,
ssl_error_reason);
return;
}
snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%d", ssl_errno);
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ssl_error);
strerror_r(save_errno, ssl_error, MAX_SSL_ERR_LEN);
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, "TLS/SSL error: %s (%d)",
ssl_error, save_errno);
}

View File

@@ -125,20 +125,18 @@ static void ma_tls_set_error(MYSQL *mysql)
char ssl_error[MAX_SSL_ERR_LEN];
const char *ssl_error_reason;
MARIADB_PVIO *pvio= mysql->net.pvio;
int save_errno= errno;
if (!ssl_errno)
{
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, "Unknown SSL error");
return;
}
if ((ssl_error_reason= ERR_reason_error_string(ssl_errno)))
if (ssl_errno && (ssl_error_reason= ERR_reason_error_string(ssl_errno)))
{
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
0, ssl_error_reason);
return;
}
snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%lu", ssl_errno);
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0, ssl_error);
strerror_r(save_errno, ssl_error, MAX_SSL_ERR_LEN);
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, "TLS/SSL error: %s (%d)",
ssl_error, save_errno);
return;
}

View File

@@ -682,7 +682,7 @@ int test_connection_timeout2(MYSQL *unused __attribute__((unused)))
SKIP_SKYSQL;
SKIP_MAXSCALE;
// SKIP_TLS;
SKIP_TLS;
mysql= mysql_init(NULL);
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (unsigned int *)&timeout);