Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit afec8e3

Browse files
committed
Patch #751916: Check for signals, fix some refcounting errors.
1 parent 2dd1ed6 commit afec8e3

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Modules/_ssl.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,17 @@ newPySSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file)
245245
ret = SSL_connect(self->ssl);
246246
err = SSL_get_error(self->ssl, ret);
247247
Py_END_ALLOW_THREADS
248+
if(PyErr_CheckSignals()) {
249+
goto fail;
250+
}
248251
if (err == SSL_ERROR_WANT_READ) {
249252
timedout = wait_for_timeout(Sock, 0);
250253
} else if (err == SSL_ERROR_WANT_WRITE) {
251254
timedout = wait_for_timeout(Sock, 1);
252255
}
253256
if (timedout) {
254-
PyErr_SetString(PySSLErrorObject, "The connect operation timed out");
255-
return NULL;
257+
errstr = "The connect operation timed out";
258+
goto fail;
256259
}
257260
} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
258261
if (ret <= 0) {
@@ -387,6 +390,9 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
387390
len = SSL_write(self->ssl, data, len);
388391
err = SSL_get_error(self->ssl, len);
389392
Py_END_ALLOW_THREADS
393+
if(PyErr_CheckSignals()) {
394+
return NULL;
395+
}
390396
if (err == SSL_ERROR_WANT_READ) {
391397
timedout = wait_for_timeout(self->Socket, 0);
392398
} else if (err == SSL_ERROR_WANT_WRITE) {
@@ -434,13 +440,18 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
434440
count = SSL_read(self->ssl, PyString_AsString(buf), len);
435441
err = SSL_get_error(self->ssl, count);
436442
Py_END_ALLOW_THREADS
443+
if(PyErr_CheckSignals()) {
444+
Py_DECREF(buf);
445+
return NULL;
446+
}
437447
if (err == SSL_ERROR_WANT_READ) {
438448
timedout = wait_for_timeout(self->Socket, 0);
439449
} else if (err == SSL_ERROR_WANT_WRITE) {
440450
timedout = wait_for_timeout(self->Socket, 1);
441451
}
442452
if (timedout) {
443453
PyErr_SetString(PySSLErrorObject, "The read operation timed out");
454+
Py_DECREF(buf);
444455
return NULL;
445456
}
446457
} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);

0 commit comments

Comments
 (0)