@@ -2352,8 +2352,7 @@ static PyObject *
2352
2352
_ssl__SSLSocket_write_impl (PySSLSocket * self , Py_buffer * b )
2353
2353
/*[clinic end generated code: output=aa7a6be5527358d8 input=77262d994fe5100a]*/
2354
2354
{
2355
- size_t count = 0 ;
2356
- int retval ;
2355
+ int len ;
2357
2356
int sockstate ;
2358
2357
_PySSLError err ;
2359
2358
int nonblocking ;
@@ -2371,6 +2370,12 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
2371
2370
Py_INCREF (sock );
2372
2371
}
2373
2372
2373
+ if (b -> len > INT_MAX ) {
2374
+ PyErr_Format (PyExc_OverflowError ,
2375
+ "string longer than %d bytes" , INT_MAX );
2376
+ goto error ;
2377
+ }
2378
+
2374
2379
if (sock != NULL ) {
2375
2380
/* just in case the blocking state of the socket has been changed */
2376
2381
nonblocking = (sock -> sock_timeout >= 0 );
@@ -2400,8 +2405,8 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
2400
2405
2401
2406
do {
2402
2407
PySSL_BEGIN_ALLOW_THREADS
2403
- retval = SSL_write_ex (self -> ssl , b -> buf , (size_t )b -> len , & count );
2404
- err = _PySSL_errno (retval == 0 , self -> ssl , retval );
2408
+ len = SSL_write (self -> ssl , b -> buf , (int )b -> len );
2409
+ err = _PySSL_errno (len <= 0 , self -> ssl , len );
2405
2410
PySSL_END_ALLOW_THREADS
2406
2411
self -> err = err ;
2407
2412
@@ -2434,11 +2439,11 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
2434
2439
err .ssl == SSL_ERROR_WANT_WRITE );
2435
2440
2436
2441
Py_XDECREF (sock );
2437
- if (retval = = 0 )
2438
- return PySSL_SetError (self , retval , __FILE__ , __LINE__ );
2442
+ if (len < = 0 )
2443
+ return PySSL_SetError (self , len , __FILE__ , __LINE__ );
2439
2444
if (PySSL_ChainExceptions (self ) < 0 )
2440
2445
return NULL ;
2441
- return PyLong_FromSize_t ( count );
2446
+ return PyLong_FromLong ( len );
2442
2447
error :
2443
2448
Py_XDECREF (sock );
2444
2449
PySSL_ChainExceptions (self );
@@ -2488,8 +2493,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
2488
2493
{
2489
2494
PyObject * dest = NULL ;
2490
2495
char * mem ;
2491
- size_t count = 0 ;
2492
- int retval ;
2496
+ int count ;
2493
2497
int sockstate ;
2494
2498
_PySSLError err ;
2495
2499
int nonblocking ;
@@ -2552,8 +2556,8 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
2552
2556
2553
2557
do {
2554
2558
PySSL_BEGIN_ALLOW_THREADS
2555
- retval = SSL_read_ex (self -> ssl , mem , ( size_t ) len , & count );
2556
- err = _PySSL_errno (retval == 0 , self -> ssl , retval );
2559
+ count = SSL_read (self -> ssl , mem , len );
2560
+ err = _PySSL_errno (count <= 0 , self -> ssl , count );
2557
2561
PySSL_END_ALLOW_THREADS
2558
2562
self -> err = err ;
2559
2563
@@ -2586,8 +2590,8 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
2586
2590
} while (err .ssl == SSL_ERROR_WANT_READ ||
2587
2591
err .ssl == SSL_ERROR_WANT_WRITE );
2588
2592
2589
- if (retval = = 0 ) {
2590
- PySSL_SetError (self , retval , __FILE__ , __LINE__ );
2593
+ if (count < = 0 ) {
2594
+ PySSL_SetError (self , count , __FILE__ , __LINE__ );
2591
2595
goto error ;
2592
2596
}
2593
2597
if (self -> exc_type != NULL )
@@ -2600,7 +2604,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
2600
2604
return dest ;
2601
2605
}
2602
2606
else {
2603
- return PyLong_FromSize_t (count );
2607
+ return PyLong_FromLong (count );
2604
2608
}
2605
2609
2606
2610
error :
0 commit comments