@@ -321,7 +321,7 @@ typedef struct {
321
321
#endif
322
322
#ifdef HAVE_ALPN
323
323
unsigned char * alpn_protocols ;
324
- int alpn_protocols_len ;
324
+ unsigned int alpn_protocols_len ;
325
325
#endif
326
326
#ifndef OPENSSL_NO_TLSEXT
327
327
PyObject * set_hostname ;
@@ -1591,7 +1591,8 @@ cipher_to_dict(const SSL_CIPHER *cipher)
1591
1591
cipher_protocol = SSL_CIPHER_get_version (cipher );
1592
1592
cipher_id = SSL_CIPHER_get_id (cipher );
1593
1593
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 );
1595
1596
if (len > 1 && buf [len - 1 ] == '\n' )
1596
1597
buf [len - 1 ] = '\0' ;
1597
1598
strength_bits = SSL_CIPHER_get_bits (cipher , & alg_bits );
@@ -2975,12 +2976,18 @@ _ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self,
2975
2976
/*[clinic end generated code: output=87599a7f76651a9b input=9bba964595d519be]*/
2976
2977
{
2977
2978
#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
+
2978
2985
PyMem_FREE (self -> alpn_protocols );
2979
2986
self -> alpn_protocols = PyMem_Malloc (protos -> len );
2980
2987
if (!self -> alpn_protocols )
2981
2988
return PyErr_NoMemory ();
2982
2989
memcpy (self -> alpn_protocols , protos -> buf , protos -> len );
2983
- self -> alpn_protocols_len = protos -> len ;
2990
+ self -> alpn_protocols_len = ( unsigned int ) protos -> len ;
2984
2991
2985
2992
if (SSL_CTX_set_alpn_protos (self -> ctx , self -> alpn_protocols , self -> alpn_protocols_len ))
2986
2993
return PyErr_NoMemory ();
@@ -4109,7 +4116,7 @@ memory_bio_dealloc(PySSLMemoryBIO *self)
4109
4116
static PyObject *
4110
4117
memory_bio_get_pending (PySSLMemoryBIO * self , void * c )
4111
4118
{
4112
- return PyLong_FromLong (BIO_ctrl_pending (self -> bio ));
4119
+ return PyLong_FromSize_t (BIO_ctrl_pending (self -> bio ));
4113
4120
}
4114
4121
4115
4122
PyDoc_STRVAR (PySSL_memory_bio_pending_doc ,
@@ -4145,7 +4152,7 @@ _ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len)
4145
4152
int avail , nbytes ;
4146
4153
PyObject * result ;
4147
4154
4148
- avail = BIO_ctrl_pending (self -> bio );
4155
+ avail = ( int ) Py_MIN ( BIO_ctrl_pending (self -> bio ), INT_MAX );
4149
4156
if ((len < 0 ) || (len > avail ))
4150
4157
len = avail ;
4151
4158
@@ -4191,7 +4198,7 @@ _ssl_MemoryBIO_write_impl(PySSLMemoryBIO *self, Py_buffer *b)
4191
4198
return NULL ;
4192
4199
}
4193
4200
4194
- nbytes = BIO_write (self -> bio , b -> buf , b -> len );
4201
+ nbytes = BIO_write (self -> bio , b -> buf , ( int ) b -> len );
4195
4202
if (nbytes < 0 ) {
4196
4203
_setSSLError (NULL , 0 , __FILE__ , __LINE__ );
4197
4204
return NULL ;
0 commit comments