From: Matt Caswell Date: Fri, 11 Mar 2016 16:47:42 +0000 (+0000) Subject: Don't clobber the last error X-Git-Tag: OpenSSL_1_1_0-pre4~50 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=81161070f8ec75ba83964e98ad70c4c4d015c276;p=oweals%2Fopenssl.git Don't clobber the last error On Windows we call WSAGetLastError() to find out the last error that happened on a socket operation. We use this to find out whether we can retry the operation or not. You are supposed to call this immediately however in a couple of places we logged an error first. This can end up making other Windows system calls to get the thread local error state. Sometimes that can clobber the error code, so if you call WSAGetLastError() later on you get a spurious response and the socket operation looks like a fatal error. Really we shouldn't be logging an error anyway if its a retryable issue. Otherwise we could end up with stale errors on the error queue. Reviewed-by: Richard Levitte --- diff --git a/crypto/bio/b_sock2.c b/crypto/bio/b_sock2.c index bf613ac228..9f092fc073 100644 --- a/crypto/bio/b_sock2.c +++ b/crypto/bio/b_sock2.c @@ -149,8 +149,10 @@ int BIO_connect(int sock, const BIO_ADDR *addr, int options) if (connect(sock, BIO_ADDR_sockaddr(addr), BIO_ADDR_sockaddr_size(addr)) == -1) { - SYSerr(SYS_F_CONNECT, get_last_socket_error()); - BIOerr(BIO_F_BIO_CONNECT, BIO_R_CONNECT_ERROR); + if (!BIO_sock_should_retry(-1)) { + SYSerr(SYS_F_CONNECT, get_last_socket_error()); + BIOerr(BIO_F_BIO_CONNECT, BIO_R_CONNECT_ERROR); + } return 0; } return 1; @@ -285,8 +287,10 @@ int BIO_accept_ex(int accept_sock, BIO_ADDR *addr_, int options) accepted_sock = accept(accept_sock, BIO_ADDR_sockaddr_noconst(addr), &len); if (accepted_sock == -1) { - SYSerr(SYS_F_ACCEPT, get_last_socket_error()); - BIOerr(BIO_F_BIO_ACCEPT_EX, BIO_R_ACCEPT_ERROR); + if (!BIO_sock_should_retry(accepted_sock)) { + SYSerr(SYS_F_ACCEPT, get_last_socket_error()); + BIOerr(BIO_F_BIO_ACCEPT_EX, BIO_R_ACCEPT_ERROR); + } return INVALID_SOCKET; }