8000 gh-115627: Fix PySSL_SetError handling SSL_ERROR_SYSCALL by keepworking · Pull Request #115628 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-115627: Fix PySSL_SetError handling SSL_ERROR_SYSCALL #115628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-115627: Fix PySSL_SetError handling SSL_ERROR_SYSCALL
  • Loading branch information
keepworking committed Mar 22, 2024
commit 0ceea40eacb63297c390032824f2b487ba36e058
25 changes: 14 additions & 11 deletions Lib/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2429,16 +2429,19 @@ 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.
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:
Expand Down Expand Up @@ -4532,8 +4535,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)'
(ssl.SSLError, OSError),
'(certificate required|EOF occurred|closed by the remote host)'
):
# receive CertificateRequest
data = s.recv(1024)
Expand Down
8 changes: 2 additions & 6 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,11 @@ PySSL_SetError(PySSLSocket *sslsock, int ret, const char *filename, int lineno)
{
if (e == 0) {
PySocketSockObject *s = GET_SOCKET(sslsock);
if (ret == 0 || (((PyObject *)s) == Py_None)) {
if (((PyObject *)s) == Py_None) {
p = PY_SSL_ERROR_EOF;
type = state->PySSLEOFErrorObject;
errstr = "EOF occurred in violation of protocol";
} else if (s && ret == -1) {
} else {
/* underlying BIO reported an I/O error */
ERR_clear_error();
#ifdef MS_WINDOWS
Expand All @@ -667,10 +667,6 @@ PySSL_SetError(PySSLSocket *sslsock, int ret, const char *filename, int lineno)
type = state->PySSLEOFErrorObject;
errstr = "EOF occurred in violation of protocol";
}
} else { /* possible? */
p = PY_SSL_ERROR_SYSCALL;
type = state->PySSLSyscallErrorObject;
errstr = "Some I/O error occurred";
}
} else {
if (ERR_GET_LIB(e) == ERR_LIB_SSL &&
Expand Down
0