@@ -321,7 +321,7 @@ typedef struct {
321321#endif
322322#ifdef HAVE_ALPN
323323 unsigned char * alpn_protocols ;
324- int alpn_protocols_len ;
324+ unsigned int alpn_protocols_len ;
325325#endif
326326#ifndef OPENSSL_NO_TLSEXT
327327 PyObject * set_hostname ;
@@ -1591,7 +1591,8 @@ cipher_to_dict(const SSL_CIPHER *cipher)
15911591 cipher_protocol = SSL_CIPHER_get_version (cipher );
15921592 cipher_id = SSL_CIPHER_get_id (cipher );
15931593 SSL_CIPHER_description (cipher , buf , sizeof (buf ) - 1 );
1594- len = strlen (buf );
1594+ /* Downcast to avoid a warning. Safe since buf is always 512 bytes */
1595+ len = (int )strlen (buf );
15951596 if (len > 1 && buf [len - 1 ] == '\n' )
15961597 buf [len - 1 ] = '\0' ;
15971598 strength_bits = SSL_CIPHER_get_bits (cipher , & alg_bits );
@@ -2975,12 +2976,18 @@ _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
29752976/*[clinic end generated code: output=87599a7f76651a9b input=9bba964595d519be]*/
29762977{
29772978#ifdef HAVE_ALPN
2979+ if (protos -> len > UINT_MAX ) {
2980+ PyErr_Format (PyExc_OverflowError ,
2981+ "protocols longer than %d bytes" , UINT_MAX );
2982+ return NULL ;
2983+ }
2984+
29782985 PyMem_FREE (self -> alpn_protocols );
29792986 self -> alpn_protocols = PyMem_Malloc (protos -> len );
29802987 if (!self -> alpn_protocols )
29812988 return PyErr_NoMemory ();
29822989 memcpy (self -> alpn_protocols , protos -> buf , protos -> len );
2983- self -> alpn_protocols_len = protos -> len ;
2990+ self -> alpn_protocols_len = ( unsigned int ) protos -> len ;
29842991
29852992 if (SSL_CTX_set_alpn_protos (self -> ctx , self -> alpn_protocols , self -> alpn_protocols_len ))
29862993 return PyErr_NoMemory ();
@@ -4109,7 +4116,7 @@ memory_bio_dealloc(PySSLMemoryBIO *self)
41094116static PyObject *
41104117memory_bio_get_pending (PySSLMemoryBIO * self , void * c )
41114118{
4112- return PyLong_FromLong (BIO_ctrl_pending (self -> bio ));
4119+ return PyLong_FromSize_t (BIO_ctrl_pending (self -> bio ));
41134120}
41144121
41154122PyDoc_STRVAR (PySSL_memory_bio_pending_doc ,
@@ -4145,7 +4152,7 @@ _ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len)
41454152 int avail , nbytes ;
41464153 PyObject * result ;
41474154
4148- avail = BIO_ctrl_pending (self -> bio );
4155+ avail = ( int ) Py_MIN ( BIO_ctrl_pending (self -> bio ), INT_MAX );
41494156 if ((len < 0 ) || (len > avail ))
41504157 len = avail ;
41514158
@@ -4191,7 +4198,7 @@ _ssl_MemoryBIO_write_impl(PySSLMemoryBIO *self, Py_buffer *b)
41914198 return NULL ;
41924199 }
41934200
4194- nbytes = BIO_write (self -> bio , b -> buf , b -> len );
4201+ nbytes = BIO_write (self -> bio , b -> buf , ( int ) b -> len );
41954202 if (nbytes < 0 ) {
41964203 _setSSLError (NULL , 0 , __FILE__ , __LINE__ );
41974204 return NULL ;
0 commit comments