@@ -2305,8 +2305,7 @@ static PyObject *
2305
2305
_ssl__SSLSocket_write_impl (PySSLSocket * self , Py_buffer * b )
2306
2306
/*[clinic end generated code: output=aa7a6be5527358d8 input=77262d994fe5100a]*/
2307
2307
{
2308
- size_t count = 0 ;
2309
- int retval ;
2308
+ int len ;
2310
2309
int sockstate ;
2311
2310
_PySSLError err ;
2312
2311
int nonblocking ;
@@ -2324,6 +2323,12 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
2324
2323
Py_INCREF (sock );
2325
2324
}
2326
2325
2326
+ if (b -> len > INT_MAX ) {
2327
+ PyErr_Format (PyExc_OverflowError ,
2328
+ "string longer than %d bytes" , INT_MAX );
2329
+ goto error ;
2330
+ }
2331
+
2327
2332
if (sock != NULL ) {
2328
2333
/* just in case the blocking state of the socket has been changed */
2329
2334
nonblocking = (sock -> sock_timeout >= 0 );
@@ -2354,8 +2359,8 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
2354
2359
2355
2360
do {
2356
2361
PySSL_BEGIN_ALLOW_THREADS
2357
- retval = SSL_write_ex (self -> ssl , b -> buf , (int )b -> len , & count );
2358
- err = _PySSL_errno (retval == 0 , self -> ssl , retval );
2362
+ len = SSL_write (self -> ssl , b -> buf , (int )b -> len );
2363
+ err = _PySSL_errno (len <= 0 , self -> ssl , len );
2359
2364
PySSL_END_ALLOW_THREADS
2360
2365
self -> err = err ;
2361
2366
@@ -2389,11 +2394,11 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
2389
2394
err .ssl == SSL_ERROR_WANT_WRITE );
2390
2395
2391
2396
Py_XDECREF (sock );
2392
- if (retval = = 0 )
2393
- return PySSL_SetError (self , retval , __FILE__ , __LINE__ );
2397
+ if (len < = 0 )
2398
+ return PySSL_SetError (self , len , __FILE__ , __LINE__ );
2394
2399
if (PySSL_ChainExceptions (self ) < 0 )
2395
2400
return NULL ;
2396
- return PyLong_FromSize_t ( count );
2401
+ return PyLong_FromLong ( len );
2397
2402
error :
2398
2403
Py_XDECREF (sock );
2399
2404
PySSL_ChainExceptions (self );
@@ -2443,8 +2448,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
2443
2448
{
2444
2449
PyObject * dest = NULL ;
2445
2450
char * mem ;
2446
- size_t count = 0 ;
2447
- int retval ;
2451
+ int count ;
2448
2452
int sockstate ;
2449
2453
_PySSLError err ;
2450
2454
int nonblocking ;
@@ -2507,8 +2511,8 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
2507
2511
2508
2512
do {
2509
2513
PySSL_BEGIN_ALLOW_THREADS
2510
- retval = SSL_read_ex (self -> ssl , mem , len , & count );
2511
- err = _PySSL_errno (retval == 0 , self -> ssl , retval );
2514
+ count = SSL_read (self -> ssl , mem , len );
2515
+ err = _PySSL_errno (count <= 0 , self -> ssl , count );
2512
2516
PySSL_END_ALLOW_THREADS
2513
2517
self -> err = err ;
2514
2518
@@ -2542,8 +2546,8 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
2542
2546
} while (err .ssl == SSL_ERROR_WANT_READ ||
2543
2547
err .ssl == SSL_ERROR_WANT_WRITE );
2544
2548
2545
- if (retval = = 0 ) {
2546
- PySSL_SetError (self , retval , __FILE__ , __LINE__ );
2549
+ if (count < = 0 ) {
2550
+ PySSL_SetError (self , count , __FILE__ , __LINE__ );
2547
2551
goto error ;
2548
2552
}
2549
2553
if (self -> exc_type != NULL )
@@ -2556,7 +2560,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
2556
2560
return dest ;
2557
2561
}
2558
2562
else {
2559
- return PyLong_FromSize_t (count );
2563
+ return PyLong_FromLong (count );
2560
2564
}
2561
2565
2562
2566
error :
0 commit comments