summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-28 02:00:46 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-28 02:00:46 (GMT)
commite245231fabb4c97521959e9ae1b45469bfad0d1e (patch)
tree3958cfd82ebbe33bcb7ebce26614cece744d7273
parentb28e91633a7bedd2d821de523b0303fee3d7e0f6 (diff)
downloadcpython-e245231fabb4c97521959e9ae1b45469bfad0d1e.zip
cpython-e245231fabb4c97521959e9ae1b45469bfad0d1e.tar.gz
cpython-e245231fabb4c97521959e9ae1b45469bfad0d1e.tar.bz2
Issue #22117: Fix ssl to use _PyTime_t API on sock_timeout
I didn't notice that the ssl module uses private attributes of socket objects.
-rw-r--r--Modules/_ssl.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index be6fca3..54f5d14 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -534,7 +534,7 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
/* If the socket is in non-blocking mode or timeout mode, set the BIO
* to non-blocking mode (blocking is the default)
*/
- if (sock && sock->sock_timeout >= 0.0) {
+ if (sock && sock->sock_timeout >= 0) {
BIO_set_nbio(SSL_get_rbio(self->ssl), 1);
BIO_set_nbio(SSL_get_wbio(self->ssl), 1);
}
@@ -576,7 +576,7 @@ static PyObject *PySSL_SSLdo_handshake(PySSLSocket *self)
Py_INCREF(sock);
/* just in case the blocking state of the socket has been changed */
- nonblocking = (sock->sock_timeout >= 0.0);
+ nonblocking = (sock->sock_timeout >= 0);
BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
}
@@ -1616,9 +1616,9 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
int rc;
/* Nothing to do unless we're in timeout mode (not non-blocking) */
- if ((s == NULL) || (s->sock_timeout == 0.0))
+ if ((s == NULL) || (s->sock_timeout == 0))
return SOCKET_IS_NONBLOCKING;
- else if (s->sock_timeout < 0.0)
+ else if (s->sock_timeout < 0)
return SOCKET_IS_BLOCKING;
/* Guard against closed socket */
@@ -1636,7 +1636,9 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
pollfd.events = writing ? POLLOUT : POLLIN;
/* s->sock_timeout is in seconds, timeout in ms */
- timeout = (int)(s->sock_timeout * 1000 + 0.5);
+ timeout = (int)_PyTime_AsMilliseconds(s->sock_timeout,
+ _PyTime_ROUND_UP);
+
PySSL_BEGIN_ALLOW_THREADS
rc = poll(&pollfd, 1, timeout);
PySSL_END_ALLOW_THREADS
@@ -1649,9 +1651,10 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
if (!_PyIsSelectable_fd(s->sock_fd))
return SOCKET_TOO_LARGE_FOR_SELECT;
- /* Construct the arguments to select */
- tv.tv_sec = (int)s->sock_timeout;
- tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
+ /* conversion was already checked for overflow when
+ the timeout was set */
+ (void)_PyTime_AsTimeval(s->sock_timeout, &tv, _PyTime_ROUND_UP);
+
FD_ZERO(&fds);
FD_SET(s->sock_fd, &fds);
@@ -1704,7 +1707,7 @@ static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args)
if (sock != NULL) {
/* just in case the blocking state of the socket has been changed */
- nonblocking = (sock->sock_timeout >= 0.0);
+ nonblocking = (sock->sock_timeout >= 0);
BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
}
@@ -1836,7 +1839,7 @@ static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args)
if (sock != NULL) {
/* just in case the blocking state of the socket has been changed */
- nonblocking = (sock->sock_timeout >= 0.0);
+ nonblocking = (sock->sock_timeout >= 0);
BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
}
@@ -1915,7 +1918,7 @@ static PyObject *PySSL_SSLshutdown(PySSLSocket *self)
Py_INCREF(sock);
/* Just in case the blocking state of the socket has been changed */
- nonblocking = (sock->sock_timeout >= 0.0);
+ nonblocking = (sock->sock_timeout >= 0);
BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
}