@@ -912,6 +912,11 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
912912 PySSL_BEGIN_ALLOW_THREADS
913913 self -> ssl = SSL_new (ctx );
914914 PySSL_END_ALLOW_THREADS
915+ if (self -> ssl == NULL) {
916+ Py_DECREF (self );
917+ _setSSLError (NULL , 0 , __FILE__ , __LINE__ );
918+ return NULL ;
919+ }
915920 SSL_set_app_data (self -> ssl , self );
916921 if (sock ) {
917922 SSL_set_fd (self -> ssl , Py_SAFE_DOWNCAST (sock -> sock_fd , SOCKET_T , int ));
@@ -1241,6 +1246,10 @@ _get_peer_alt_names (X509 *certificate) {
12411246
12421247 /* get a memory buffer */
12431248 biobuf = BIO_new (BIO_s_mem ());
1249+ if (biobuf == NULL ) {
1250+ PyErr_SetString (PySSLErrorObject , "failed to allocate BIO" );
1251+ return NULL ;
1252+ }
12441253
12451254 names = (GENERAL_NAMES * )X509_get_ext_d2i (
12461255 certificate , NID_subject_alt_name , NULL , NULL );
@@ -1593,6 +1602,10 @@ _decode_certificate(X509 *certificate) {
15931602
15941603 /* get a memory buffer */
15951604 biobuf = BIO_new (BIO_s_mem ());
1605+ if (biobuf == NULL ) {
1606+ PyErr_SetString (PySSLErrorObject , "failed to allocate BIO" );
1607+ goto fail0 ;
1608+ }
15961609
15971610 (void ) BIO_reset (biobuf );
15981611 serialNumber = X509_get_serialNumber (certificate );
0 commit comments