Skip to content

Commit 3ce51b0

Browse files
committed
Fix for CONC-587:
Since alerts may happen after handshake (for example with described test in CONC-587 using TLSv1.3 protocol or by renegotiation) the tls error message needs to be retrieved if error is a protocol error (SSL_ERROR_SSL) and/or if errno was not set.
1 parent b973c75 commit 3ce51b0

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

libmariadb/mariadb_lib.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,16 @@ ma_net_safe_read(MYSQL *mysql)
202202
if (len == packet_error || len == 0)
203203
{
204204
end_server(mysql);
205-
my_set_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ?
206-
CR_NET_PACKET_TOO_LARGE:
207-
CR_SERVER_LOST,
208-
SQLSTATE_UNKNOWN, 0, errno);
205+
#ifdef HAVE_TLS
206+
/* don't overwrite possible tls protocol errors */
207+
if (net->last_errno != CR_SSL_CONNECTION_ERROR)
208+
#endif
209+
{
210+
my_set_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ?
211+
CR_NET_PACKET_TOO_LARGE:
212+
CR_SERVER_LOST,
213+
SQLSTATE_UNKNOWN, 0, errno);
214+
}
209215
return(packet_error);
210216
}
211217
if (net->read_pos[0] == 255)

libmariadb/secure/openssl.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,14 @@ ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
591591
{
592592
int error= SSL_get_error((SSL *)ctls->ssl, rc);
593593
if (error != SSL_ERROR_WANT_READ)
594+
{
595+
if (error == SSL_ERROR_SSL || errno == 0)
596+
{
597+
MYSQL *mysql= SSL_get_app_data(ctls->ssl);
598+
ma_tls_set_error(mysql);
599+
}
594600
return rc;
601+
}
595602
if (pvio->methods->wait_io_or_timeout(pvio, TRUE, pvio->mysql->options.read_timeout) < 1)
596603
return rc;
597604
}
@@ -607,7 +614,14 @@ ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
607614
{
608615
int error= SSL_get_error((SSL *)ctls->ssl, rc);
609616
if (error != SSL_ERROR_WANT_WRITE)
617+
{
618+
if (error == SSL_ERROR_SSL || errno == 0)
619+
{
620+
MYSQL *mysql= SSL_get_app_data(ctls->ssl);
621+
ma_tls_set_error(mysql);
622+
}
610623
return rc;
624+
}
611625
if (pvio->methods->wait_io_or_timeout(pvio, TRUE, pvio->mysql->options.write_timeout) < 1)
612626
return rc;
613627
}

0 commit comments

Comments
 (0)