1
0
mirror of https://github.com/moparisthebest/curl synced 2025-03-01 01:41:50 -05:00

openssl: stricter connection check function

- In the case of recv error, limit returning 'connection still in place'
to EINPROGRESS, EAGAIN and EWOULDBLOCK.

This is an improvement on the parent commit which changed the openssl
connection check to use recv MSG_PEEK instead of SSL_peek.

Ref: https://github.com/curl/curl/commit/856baf5#comments
This commit is contained in:
Jay Satiro 2016-05-11 21:21:15 -04:00
parent 856baf5a46
commit 2968c83967

View File

@ -750,7 +750,7 @@ void Curl_ossl_cleanup(void)
} }
/* /*
* This function uses SSL_peek to determine connection status. * This function is used to determine connection status.
* *
* Return codes: * Return codes:
* 1 means the connection is still in place * 1 means the connection is still in place
@ -759,17 +759,46 @@ void Curl_ossl_cleanup(void)
*/ */
int Curl_ossl_check_cxn(struct connectdata *conn) int Curl_ossl_check_cxn(struct connectdata *conn)
{ {
/* SSL_peek takes data out of the raw recv buffer without peeking so we use
recv MSG_PEEK instead. Bug #795 */
#ifdef MSG_PEEK #ifdef MSG_PEEK
char buf; char buf;
if(recv((RECV_TYPE_ARG1)conn->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf, int nread;
(RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) { nread = recv((RECV_TYPE_ARG1)conn->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf,
(RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK);
if(nread == 0)
return 0; /* connection has been closed */ return 0; /* connection has been closed */
} else if(nread == 1)
else
return 1; /* connection still in place */ return 1; /* connection still in place */
#else else if(nread == -1) {
return -1; /* connection status unknown */ int err = SOCKERRNO;
if(err == EINPROGRESS ||
#if defined(EAGAIN) && (EAGAIN != EWOULDBLOCK)
err == EAGAIN ||
#endif #endif
err == EWOULDBLOCK)
return 1; /* connection still in place */
if(err == ECONNRESET ||
#ifdef ECONNABORTED
err == ECONNABORTED ||
#endif
#ifdef ENETDOWN
err == ENETDOWN ||
#endif
#ifdef ENETRESET
err == ENETRESET ||
#endif
#ifdef ESHUTDOWN
err == ESHUTDOWN ||
#endif
#ifdef ETIMEDOUT
err == ETIMEDOUT ||
#endif
err == ENOTCONN)
return 0; /* connection has been closed */
}
#endif
return -1; /* connection status unknown */
} }
/* Selects an OpenSSL crypto engine /* Selects an OpenSSL crypto engine