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

Fix for CONC-608: Replace server error codes

Since Connector/C is not able to retrieve
error strings for server error codes, the following
error codes were replaced:

- ER_NET_PACKET_TOO_LARFE by CR_NET_PACKET_TOO_LARGE
- ER_OUT_OF_RESOURCES by CR_OUT_OF_MEMORY
- ER_NET_WRITE_ERROR by CR_ERR_NET_WRITE (new constant)
- ER_NET_UNCOMPRESS_ERROR by CR_ERR_NET_UNCOMPRESS (new constant)
This commit is contained in:
Georg Richter
2022-07-21 09:11:29 +02:00
parent 9a572bc548
commit cdb6e90c35
5 changed files with 25 additions and 9 deletions

View File

@@ -101,7 +101,11 @@ extern const char *mariadb_client_errors[]; /* Error messages */
#define CR_BULK_WITHOUT_PARAMETERS 5006
#define CR_INVALID_STMT 5007
#define CR_VERSION_MISMATCH 5008
#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_VERSION_MISMATCH
#define CR_MARIADB_LAST_ERROR CR_ERR_NET_UNCOMPRESS
#endif

View File

@@ -159,6 +159,13 @@ const char *mariadb_client_errors[] =
/* 5006 */ "Bulk operation without parameters is not supported",
/* 5007 */ "Invalid statement handle",
/* 5008 */ "Unsupported version %d. Supported versions are in the range %d - %d",
/* 5009 */ "",
/* 5010 */ "",
/* 5011 */ "",
/* 5012 */ "",
/* 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((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

@@ -1680,7 +1680,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)
return 0;

View File

@@ -685,7 +685,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);