@@ -911,6 +911,11 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
911911 PySSL_BEGIN_ALLOW_THREADS
912912 self -> ssl = SSL_new (ctx );
913913 PySSL_END_ALLOW_THREADS
914+ if (self -> ssl == NULL) {
915+ Py_DECREF (self );
916+ _setSSLError (NULL , 0 , __FILE__ , __LINE__ );
917+ return NULL ;
918+ }
914919 SSL_set_app_data (self -> ssl , self );
915920 if (sock ) {
916921 SSL_set_fd (self -> ssl , Py_SAFE_DOWNCAST (sock -> sock_fd , SOCKET_T , int ));
@@ -1240,6 +1245,10 @@ _get_peer_alt_names (X509 *certificate) {
12401245
12411246 /* get a memory buffer */
12421247 biobuf = BIO_new (BIO_s_mem ());
1248+ if (biobuf == NULL ) {
1249+ PyErr_SetString (PySSLErrorObject , "failed to allocate BIO" );
1250+ return NULL ;
1251+ }
12431252
12441253 names = (GENERAL_NAMES * )X509_get_ext_d2i (
12451254 certificate , NID_subject_alt_name , NULL , NULL );
@@ -1592,6 +1601,10 @@ _decode_certificate(X509 *certificate) {
15921601
15931602 /* get a memory buffer */
15941603 biobuf = BIO_new (BIO_s_mem ());
1604+ if (biobuf == NULL ) {
1605+ PyErr_SetString (PySSLErrorObject , "failed to allocate BIO" );
1606+ goto fail0 ;
1607+ }
15951608
15961609 (void ) BIO_reset (biobuf );
15971610 serialNumber = X509_get_serialNumber (certificate );
0 commit comments