Issue #9177: Calling read() or write() now raises ValueError, not AttributeError, on a closed SSL socket.
Patch by Senko Rasic.
This commit is contained in:
parent
60d634ae4a
commit
60a26e0516
|
@ -402,6 +402,8 @@ class SSLSocket(socket):
|
||||||
Return zero-length string on EOF."""
|
Return zero-length string on EOF."""
|
||||||
|
|
||||||
self._checkClosed()
|
self._checkClosed()
|
||||||
|
if not self._sslobj:
|
||||||
|
raise ValueError("Read on closed or unwrapped SSL socket.")
|
||||||
try:
|
try:
|
||||||
if buffer is not None:
|
if buffer is not None:
|
||||||
v = self._sslobj.read(len, buffer)
|
v = self._sslobj.read(len, buffer)
|
||||||
|
@ -422,6 +424,8 @@ class SSLSocket(socket):
|
||||||
number of bytes of DATA actually transmitted."""
|
number of bytes of DATA actually transmitted."""
|
||||||
|
|
||||||
self._checkClosed()
|
self._checkClosed()
|
||||||
|
if not self._sslobj:
|
||||||
|
raise ValueError("Write on closed or unwrapped SSL socket.")
|
||||||
return self._sslobj.write(data)
|
return self._sslobj.write(data)
|
||||||
|
|
||||||
def getpeercert(self, binary_form=False):
|
def getpeercert(self, binary_form=False):
|
||||||
|
|
|
@ -2311,6 +2311,21 @@ else:
|
||||||
self.assertEqual(cm.exception.reason, 'TLSV1_ALERT_INTERNAL_ERROR')
|
self.assertEqual(cm.exception.reason, 'TLSV1_ALERT_INTERNAL_ERROR')
|
||||||
self.assertIn("TypeError", stderr.getvalue())
|
self.assertIn("TypeError", stderr.getvalue())
|
||||||
|
|
||||||
|
def test_read_write_after_close_raises_valuerror(self):
|
||||||
|
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
||||||
|
context.verify_mode = ssl.CERT_REQUIRED
|
||||||
|
context.load_verify_locations(CERTFILE)
|
||||||
|
context.load_cert_chain(CERTFILE)
|
||||||
|
server = ThreadedEchoServer(context=context, chatty=False)
|
||||||
|
|
||||||
|
with server:
|
||||||
|
s = context.wrap_socket(socket.socket())
|
||||||
|
s.connect((HOST, server.port))
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
self.assertRaises(ValueError, s.read, 1024)
|
||||||
|
self.assertRaises(ValueError, s.write, 'hello')
|
||||||
|
|
||||||
|
|
||||||
def test_main(verbose=False):
|
def test_main(verbose=False):
|
||||||
if support.verbose:
|
if support.verbose:
|
||||||
|
|
|
@ -1021,6 +1021,7 @@ Jérôme Radix
|
||||||
Burton Radons
|
Burton Radons
|
||||||
Jeff Ramnani
|
Jeff Ramnani
|
||||||
Brodie Rao
|
Brodie Rao
|
||||||
|
Senko Rasic
|
||||||
Antti Rasinen
|
Antti Rasinen
|
||||||
Sridhar Ratnakumar
|
Sridhar Ratnakumar
|
||||||
Ysj Ray
|
Ysj Ray
|
||||||
|
|
|
@ -159,6 +159,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #9177: Calling read() or write() now raises ValueError, not
|
||||||
|
AttributeError, on a closed SSL socket. Patch by Senko Rasic.
|
||||||
|
|
||||||
- Issue #18513: Fix behaviour of cmath.rect w.r.t. signed zeros on OS X 10.8 +
|
- Issue #18513: Fix behaviour of cmath.rect w.r.t. signed zeros on OS X 10.8 +
|
||||||
gcc.
|
gcc.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue