@@ -2302,8 +2302,7 @@ static PyObject *
2302
2302
_ssl__SSLSocket_write_impl (PySSLSocket * self , Py_buffer * b )
2303
2303
/*[clinic end generated code: output=aa7a6be5527358d8 input=77262d994fe5100a]*/
2304
2304
{
2305
- size_t count = 0 ;
2306
- int retval ;
2305
+ int len ;
2307
2306
int sockstate ;
2308
2307
_PySSLError err ;
2309
2308
int nonblocking ;
@@ -2321,6 +2320,12 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
2321
2320
Py_INCREF (sock );
2322
2321
}
2323
2322
2323
+ if (b -> len > INT_MAX ) {
2324
+ PyErr_Format (PyExc_OverflowError ,
2325
+ "string longer than %d bytes" , INT_MAX );
2326
+ goto error ;
2327
+ }
2328
+
2324
2329
if (sock != NULL ) {
2325
2330
/* just in case the blocking state of the socket has been changed */
2326
2331
nonblocking = (sock -> sock_timeout >= 0 );
@@ -2351,8 +2356,8 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
2351
2356
2352
2357
do {
2353
2358
PySSL_BEGIN_ALLOW_THREADS
2354
- retval = SSL_write_ex (self -> ssl , b -> buf , (int )b -> len , & count );
2355
- err = _PySSL_errno (retval == 0 , self -> ssl , retval );
2359
+ len = SSL_write (self -> ssl , b -> buf , (int )b -> len );
2360
+ err = _PySSL_errno (len <= 0 , self -> ssl , len );
2356
2361
PySSL_END_ALLOW_THREADS
2357
2362
self -> err = err ;
2358
2363
@@ -2386,11 +2391,11 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
2386
2391
err .ssl == SSL_ERROR_WANT_WRITE );
2387
2392
2388
2393
Py_XDECREF (sock );
2389
- if (retval = = 0 )
2390
- return PySSL_SetError (self , retval , __FILE__ , __LINE__ );
2394
+ if (len < = 0 )
2395
+ return PySSL_SetError (self , len , __FILE__ , __LINE__ );
2391
2396
if (PySSL_ChainExceptions (self ) < 0 )
2392
2397
return NULL ;
2393
- return PyLong_FromSize_t ( count );
2398
+ return PyLong_FromLong ( len );
2394
2399
error :
2395
2400
Py_XDECREF (sock );
2396
2401
PySSL_ChainExceptions (self );
@@ -2440,8 +2445,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
2440
2445
{
2441
2446
PyObject * dest = NULL ;
2442
2447
char * mem ;
2443
- size_t count = 0 ;
2444
- int retval ;
2448
+ int count ;
2445
2449
int sockstate ;
2446
2450
_PySSLError err ;
2447
2451
int nonblocking ;
@@ -2504,8 +2508,8 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
2504
2508
2505
2509
do {
2506
2510
PySSL_BEGIN_ALLOW_THREADS
2507
- retval = SSL_read_ex (self -> ssl , mem , len , & count );
2508
- err = _PySSL_errno (retval == 0 , self -> ssl , retval );
2511
+ count = SSL_read (self -> ssl , mem , len );
2512
+ err = _PySSL_errno (count <= 0 , self -> ssl , count );
2509
2513
PySSL_END_ALLOW_THREADS
2510
2514
self -> err = err ;
2511
2515
@@ -2539,8 +2543,8 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
2539
2543
} while (err .ssl == SSL_ERROR_WANT_READ ||
2540
2544
err .ssl == SSL_ERROR_WANT_WRITE );
2541
2545
2542
- if (retval = = 0 ) {
2543
- PySSL_SetError (self , retval , __FILE__ , __LINE__ );
2546
+ if (count < = 0 ) {
2547
+ PySSL_SetError (self , count , __FILE__ , __LINE__ );
2544
2548
goto error ;
2545
2549
}
2546
2550
if (self -> exc_type != NULL )
@@ -2553,7 +2557,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
2553
2557
return dest ;
2554
2558
}
2555
2559
else {
2556
- return PyLong_FromSize_t (count );
2560
+ return PyLong_FromLong (count );
2557
2561
}
2558
2562
2559
2563
error :
0 commit comments