summaryrefslogtreecommitdiffstats
path: root/Modules/_ssl.c
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2018-12-07 10:11:30 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-12-07 10:11:30 (GMT)
commit4c49da0cb7434c676d70b9ccf38aca82ac0d64a9 (patch)
treeaae3660f9a5bc462830107cf2311b2557898e268 /Modules/_ssl.c
parent3a521f0b6167628f975c773b56c7daf8d33d6f40 (diff)
downloadcpython-4c49da0cb7434c676d70b9ccf38aca82ac0d64a9.zip
cpython-4c49da0cb7434c676d70b9ccf38aca82ac0d64a9.tar.gz
cpython-4c49da0cb7434c676d70b9ccf38aca82ac0d64a9.tar.bz2
bpo-35436: Add missing PyErr_NoMemory() calls and other minor bug fixes. (GH-11015)
Set MemoryError when appropriate, add missing failure checks, and fix some potential leaks.
Diffstat (limited to 'Modules/_ssl.c')
-rw-r--r--Modules/_ssl.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 85819f5..269f003 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -911,6 +911,11 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
PySSL_BEGIN_ALLOW_THREADS
self->ssl = SSL_new(ctx);
PySSL_END_ALLOW_THREADS
+ if (self->ssl == NULL) {
+ Py_DECREF(self);
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ return NULL;
+ }
SSL_set_app_data(self->ssl, self);
if (sock) {
SSL_set_fd(self->ssl, Py_SAFE_DOWNCAST(sock->sock_fd, SOCKET_T, int));
@@ -1240,6 +1245,10 @@ _get_peer_alt_names (X509 *certificate) {
/* get a memory buffer */
biobuf = BIO_new(BIO_s_mem());
+ if (biobuf == NULL) {
+ PyErr_SetString(PySSLErrorObject, "failed to allocate BIO");
+ return NULL;
+ }
names = (GENERAL_NAMES *)X509_get_ext_d2i(
certificate, NID_subject_alt_name, NULL, NULL);
@@ -1592,6 +1601,10 @@ _decode_certificate(X509 *certificate) {
/* get a memory buffer */
biobuf = BIO_new(BIO_s_mem());
+ if (biobuf == NULL) {
+ PyErr_SetString(PySSLErrorObject, "failed to allocate BIO");
+ goto fail0;
+ }
(void) BIO_reset(biobuf);
serialNumber = X509_get_serialNumber(certificate);