mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-115627: Fix PySSL_SetError handling SSL_ERROR_SYSCALL (GH-115628)
Python 3.10 changed from using SSL_write() and SSL_read() to SSL_write_ex() and SSL_read_ex(), but did not update handling of the return value. Change error handling so that the return value is not examined. OSError (not EOF) is now returned when retval is 0. According to *recent* man pages of all functions for which we call PySSL_SetError, (in OpenSSL 3.0 and 1.1.1), their return value should be used to determine whether an error happened (i.e. if PySSL_SetError should be called), but not what kind of error happened (so, PySSL_SetError shouldn't need retval). To get the error, we need to use SSL_get_error. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
d52bdfb19f
commit
ea9a296fce
3 changed files with 35 additions and 43 deletions
|
|
@ -2429,16 +2429,18 @@ def run(self):
|
|||
self.write(msg.lower())
|
||||
except OSError as e:
|
||||
# handles SSLError and socket errors
|
||||
if isinstance(e, ConnectionError):
|
||||
# OpenSSL 1.1.1 sometimes raises
|
||||
# ConnectionResetError when connection is not
|
||||
# shut down gracefully.
|
||||
if self.server.chatty and support.verbose:
|
||||
print(f" Connection reset by peer: {self.addr}")
|
||||
|
||||
self.close()
|
||||
self.running = False
|
||||
return
|
||||
if self.server.chatty and support.verbose:
|
||||
if isinstance(e, ConnectionError):
|
||||
# OpenSSL 1.1.1 sometimes raises
|
||||
# ConnectionResetError when connection is not
|
||||
# shut down gracefully.
|
||||
print(
|
||||
f" Connection reset by peer: {self.addr}"
|
||||
)
|
||||
else:
|
||||
handle_error("Test server failure:\n")
|
||||
handle_error("Test server failure:\n")
|
||||
try:
|
||||
self.write(b"ERROR\n")
|
||||
except OSError:
|
||||
|
|
@ -3166,8 +3168,8 @@ def test_wrong_cert_tls13(self):
|
|||
suppress_ragged_eofs=False) as s:
|
||||
s.connect((HOST, server.port))
|
||||
with self.assertRaisesRegex(
|
||||
ssl.SSLError,
|
||||
'alert unknown ca|EOF occurred|TLSV1_ALERT_UNKNOWN_CA'
|
||||
OSError,
|
||||
'alert unknown ca|EOF occurred|TLSV1_ALERT_UNKNOWN_CA|closed by the remote host|Connection reset by peer'
|
||||
):
|
||||
# TLS 1.3 perform client cert exchange after handshake
|
||||
s.write(b'data')
|
||||
|
|
@ -4532,8 +4534,8 @@ def msg_cb(conn, direction, version, content_type, msg_type, data):
|
|||
# test sometimes fails with EOF error. Test passes as long as
|
||||
# server aborts connection with an error.
|
||||
with self.assertRaisesRegex(
|
||||
ssl.SSLError,
|
||||
'(certificate required|EOF occurred)'
|
||||
OSError,
|
||||
'certificate required|EOF occurred|closed by the remote host|Connection reset by peer'
|
||||
):
|
||||
# receive CertificateRequest
|
||||
data = s.recv(1024)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue