diff --git a/libmariadb/mariadb_lib.c b/libmariadb/mariadb_lib.c index b3edfe2e2..095d1cb59 100644 --- a/libmariadb/mariadb_lib.c +++ b/libmariadb/mariadb_lib.c @@ -202,10 +202,16 @@ ma_net_safe_read(MYSQL *mysql) if (len == packet_error || len == 0) { end_server(mysql); - my_set_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ? - CR_NET_PACKET_TOO_LARGE: - CR_SERVER_LOST, - SQLSTATE_UNKNOWN, 0, errno); +#ifdef HAVE_TLS + /* don't overwrite possible tls protocol errors */ + if (net->last_errno != CR_SSL_CONNECTION_ERROR) +#endif + { + my_set_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ? + CR_NET_PACKET_TOO_LARGE: + CR_SERVER_LOST, + SQLSTATE_UNKNOWN, 0, errno); + } return(packet_error); } if (net->read_pos[0] == 255) diff --git a/libmariadb/secure/openssl.c b/libmariadb/secure/openssl.c index 9196a0cb1..5e29ef6f3 100644 --- a/libmariadb/secure/openssl.c +++ b/libmariadb/secure/openssl.c @@ -591,7 +591,14 @@ ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length) { int error= SSL_get_error((SSL *)ctls->ssl, rc); if (error != SSL_ERROR_WANT_READ) + { + if (error == SSL_ERROR_SSL || errno == 0) + { + MYSQL *mysql= SSL_get_app_data(ctls->ssl); + ma_tls_set_error(mysql); + } return rc; + } if (pvio->methods->wait_io_or_timeout(pvio, TRUE, pvio->mysql->options.read_timeout) < 1) return rc; } @@ -607,7 +614,14 @@ ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length) { int error= SSL_get_error((SSL *)ctls->ssl, rc); if (error != SSL_ERROR_WANT_WRITE) + { + if (error == SSL_ERROR_SSL || errno == 0) + { + MYSQL *mysql= SSL_get_app_data(ctls->ssl); + ma_tls_set_error(mysql); + } return rc; + } if (pvio->methods->wait_io_or_timeout(pvio, TRUE, pvio->mysql->options.write_timeout) < 1) return rc; }