diff --git a/common.h b/common.h index 4bdb577..fd365e3 100644 --- a/common.h +++ b/common.h @@ -118,6 +118,7 @@ static int __attribute__((unused)) ssl_write_with_timeout(SSL *ssl, int fd, char } static int __attribute__((unused)) ssl_read_with_timeout(SSL *ssl, int fd, void *buf, size_t num, int timeout){ + errno = 0; /* see commit message */ while (1) { int status = SSL_read(ssl, buf, num); if (status > 0) @@ -130,7 +131,7 @@ static int __attribute__((unused)) ssl_read_with_timeout(SSL *ssl, int fd, void return -1; continue; case SSL_ERROR_SYSCALL: - if (errno==0) { + if (errno == 0) { COMMON_LOG(LOG_ERR, "%s: unexpected EOF from peer", __func__); errno = ECONNABORTED; return -1; @@ -148,6 +149,7 @@ static int __attribute__((unused)) ssl_read_with_timeout(SSL *ssl, int fd, void } static int __attribute__((unused)) ssl_accept_with_timeout(SSL *ssl, int fd, int timeout) { + errno = 0; /* see commit message */ while (1) { int status = SSL_accept(ssl); if (status == 1) @@ -160,6 +162,11 @@ static int __attribute__((unused)) ssl_accept_with_timeout(SSL *ssl, int fd, in return -1; continue; case SSL_ERROR_SYSCALL: + if (errno == 0) { + COMMON_LOG(LOG_ERR, "%s: unexpected EOF from peer", __func__); + errno = ECONNABORTED; + return -1; + } COMMON_LOG(LOG_ERR, "%s: %m", __func__); return -1; case SSL_ERROR_SSL: