From bdbc67b188841f4829306a26ec4f57cd38acee02 Mon Sep 17 00:00:00 2001 From: Bruno Silvestre Date: Sat, 29 May 2021 10:11:02 -0300 Subject: [PATCH] Move the fix of SSL_get_error() in OpenSSL 1.1.1 Moving to lsec_socket_error() coverts better 'errno == 0' with SSL_ERROR_SYSCALL. --- src/compat.h | 6 ++++++ src/ssl.c | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/compat.h b/src/compat.h index 00d320c..8848f3d 100644 --- a/src/compat.h +++ b/src/compat.h @@ -48,4 +48,10 @@ //------------------------------------------------------------------------------ +#if !defined(LIBRESSL_VERSION_NUMBER) && ((OPENSSL_VERSION_NUMBER & 0xFFFFF000L) == 0x10101000L) +#define LSEC_OPENSSL_1_1_1 +#endif + +//------------------------------------------------------------------------------ + #endif diff --git a/src/ssl.c b/src/ssl.c index 82ed595..2cd213f 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -48,6 +48,11 @@ static int lsec_socket_error() #if defined(WIN32) return WSAGetLastError(); #else +#if defined(LSEC_OPENSSL_1_1_1) + // Bug in OpenSSL 1.1.1 + if (errno == 0) + return LSEC_IO_SSL; +#endif return errno; #endif } @@ -182,10 +187,6 @@ static int ssl_send(void *ctx, const char *data, size_t count, size_t *sent, ssl->error = SSL_ERROR_SSL; return LSEC_IO_SSL; } - /* Return failure when SSL reports syscall error - * but errno is not set to break send operation. */ - if (errno == 0) - return LSEC_IO_SSL; if (err == 0) return IO_CLOSED; return lsec_socket_error();