@@ -496,7 +496,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
496496 if (!PyArg_ParseTuple (args , "|i:read" , & len ))
497497 return NULL ;
498498
499- if (!(buf = PyString_FromStringAndSize ((char * ) 0 , len )))
499+ if (!(buf = PyBytes_FromStringAndSize ((char * ) 0 , len )))
500500 return NULL ;
501501
502502 /* first check if there are bytes ready to be read */
@@ -518,7 +518,7 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
518518 do {
519519 err = 0 ;
520520 Py_BEGIN_ALLOW_THREADS
521- count = SSL_read (self -> ssl , PyString_AsString (buf ), len );
521+ count = SSL_read (self -> ssl , PyBytes_AS_STRING (buf ), len );
522522 err = SSL_get_error (self -> ssl , count );
523523 Py_END_ALLOW_THREADS
524524 if (PyErr_CheckSignals ()) {
@@ -545,12 +545,15 @@ static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args)
545545 return PySSL_SetError (self , count );
546546 }
547547 if (count != len )
548- _PyString_Resize (& buf , count );
548+ if (PyBytes_Resize (buf , count ) < 0 ) {
549+ Py_DECREF (buf );
550+ return NULL ;
551+ }
549552 return buf ;
550553}
551554
552555PyDoc_STRVAR (PySSL_SSLread_doc ,
553- "read([len]) -> string \n\
556+ "read([len]) -> bytes \n\
554557\n\
555558Read up to len bytes from the SSL socket." );
556559
0 commit comments