aboutsummaryrefslogtreecommitdiff
path: root/crypto/bio
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2016-03-11 16:47:42 +0000
committerMatt Caswell <matt@openssl.org>2016-03-11 21:32:13 +0000
commit81161070f8ec75ba83964e98ad70c4c4d015c276 (patch)
tree23ca623e5315a32131f9255a06f4eb56741d4f27 /crypto/bio
parent642befa16e42feadd4d8d843a6d563ae4d161171 (diff)
downloadopenssl-81161070f8ec75ba83964e98ad70c4c4d015c276.zip
openssl-81161070f8ec75ba83964e98ad70c4c4d015c276.tar.gz
openssl-81161070f8ec75ba83964e98ad70c4c4d015c276.tar.bz2
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 <levitte@openssl.org>
Diffstat (limited to 'crypto/bio')
-rw-r--r--crypto/bio/b_sock2.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/crypto/bio/b_sock2.c b/crypto/bio/b_sock2.c
index bf613ac..9f092fc 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;
}