-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-140795: Remove 'exc' field in SSLObject #143491
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -360,11 +360,6 @@ typedef struct { | |||||
| enum py_ssl_server_or_client socket_type; | ||||||
| PyObject *owner; /* Python level "owner" passed to servername callback */ | ||||||
| PyObject *server_hostname; | ||||||
| /* Some SSL callbacks don't have error reporting. Callback wrappers | ||||||
| * store exception information on the socket. The handshake, read, write, | ||||||
| * and shutdown methods check for chained exceptions. | ||||||
| */ | ||||||
| PyObject *exc; | ||||||
| } PySSLSocket; | ||||||
|
|
||||||
| #define PySSLSocket_CAST(op) ((PySSLSocket *)(op)) | ||||||
|
|
@@ -657,18 +652,12 @@ fill_and_set_sslerror(_sslmodulestate *state, | |||||
| PyUnicodeWriter_Discard(writer); | ||||||
| } | ||||||
|
|
||||||
| static int | ||||||
| PySSL_ChainExceptions(PySSLSocket *sslsock) { | ||||||
| if (sslsock->exc == NULL) | ||||||
| return 0; | ||||||
|
|
||||||
| _PyErr_ChainExceptions1(sslsock->exc); | ||||||
| sslsock->exc = NULL; | ||||||
| return -1; | ||||||
| } | ||||||
|
|
||||||
| // Set the appropriate SSL error exception. | ||||||
| // err - error information from SSL and libc | ||||||
| // exc - if not NULL, an exception from _debughelpers.c callback to be chained | ||||||
| static PyObject * | ||||||
| PySSL_SetError(PySSLSocket *sslsock, _PySSLError err, const char *filename, int lineno) | ||||||
| PySSL_SetError(PySSLSocket *sslsock, _PySSLError err, PyObject *exc, | ||||||
| const char *filename, int lineno) | ||||||
| { | ||||||
| PyObject *type; | ||||||
| char *errstr = NULL; | ||||||
|
|
@@ -776,7 +765,7 @@ PySSL_SetError(PySSLSocket *sslsock, _PySSLError err, const char *filename, int | |||||
| } | ||||||
| fill_and_set_sslerror(state, sslsock, type, p, errstr, lineno, e); | ||||||
| ERR_clear_error(); | ||||||
| PySSL_ChainExceptions(sslsock); | ||||||
| _PyErr_ChainExceptions1(exc); // chain any exceptions from callbacks | ||||||
| return NULL; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -908,7 +897,6 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock, | |||||
| self->shutdown_seen_zero = 0; | ||||||
| self->owner = NULL; | ||||||
| self->server_hostname = NULL; | ||||||
| self->exc = NULL; | ||||||
|
|
||||||
| /* Make sure the SSL error state is initialized */ | ||||||
| ERR_clear_error(); | ||||||
|
|
@@ -1029,6 +1017,7 @@ _ssl__SSLSocket_do_handshake_impl(PySSLSocket *self) | |||||
| { | ||||||
| int ret; | ||||||
| _PySSLError err; | ||||||
| PyObject *exc = NULL; | ||||||
| int sockstate, nonblocking; | ||||||
| PySocketSockObject *sock = GET_SOCKET(self); | ||||||
| PyTime_t timeout, deadline = 0; | ||||||
|
|
@@ -1064,6 +1053,12 @@ _ssl__SSLSocket_do_handshake_impl(PySSLSocket *self) | |||||
| Py_END_ALLOW_THREADS; | ||||||
| _PySSL_FIX_ERRNO; | ||||||
|
|
||||||
| // Get any exception that occurred in a debughelpers.c callback | ||||||
| exc = PyErr_GetRaisedException(); | ||||||
picnixz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| if (exc != NULL) { | ||||||
| break; | ||||||
| } | ||||||
|
|
||||||
| if (PyErr_CheckSignals()) | ||||||
| goto error; | ||||||
|
|
||||||
|
|
@@ -1098,13 +1093,14 @@ _ssl__SSLSocket_do_handshake_impl(PySSLSocket *self) | |||||
| Py_XDECREF(sock); | ||||||
|
|
||||||
| if (ret < 1) | ||||||
| return PySSL_SetError(self, err, __FILE__, __LINE__); | ||||||
| if (PySSL_ChainExceptions(self) < 0) | ||||||
| return PySSL_SetError(self, err, exc, __FILE__, __LINE__); | ||||||
| if (exc != NULL) { | ||||||
| PyErr_SetRaisedException(exc); | ||||||
| return NULL; | ||||||
| } | ||||||
| Py_RETURN_NONE; | ||||||
| error: | ||||||
| Py_XDECREF(sock); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might add: |
||||||
| PySSL_ChainExceptions(self); | ||||||
| return NULL; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -2434,17 +2430,7 @@ _ssl__SSLSocket_owner_set_impl(PySSLSocket *self, PyObject *value) | |||||
| static int | ||||||
| PySSL_traverse(PyObject *op, visitproc visit, void *arg) | ||||||
| { | ||||||
| PySSLSocket *self = PySSLSocket_CAST(op); | ||||||
| Py_VISIT(self->exc); | ||||||
| Py_VISIT(Py_TYPE(self)); | ||||||
| return 0; | ||||||
| } | ||||||
|
|
||||||
| static int | ||||||
| PySSL_clear(PyObject *op) | ||||||
| { | ||||||
| PySSLSocket *self = PySSLSocket_CAST(op); | ||||||
| Py_CLEAR(self->exc); | ||||||
| Py_VISIT(Py_TYPE(op)); | ||||||
| return 0; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -2619,6 +2605,7 @@ _ssl__SSLSocket_sendfile_impl(PySSLSocket *self, int fd, Py_off_t offset, | |||||
| Py_ssize_t retval; | ||||||
| int sockstate; | ||||||
| _PySSLError err; | ||||||
| PyObject *exc = NULL; | ||||||
| PySocketSockObject *sock = GET_SOCKET(self); | ||||||
| PyTime_t timeout, deadline = 0; | ||||||
| int has_timeout; | ||||||
|
|
@@ -2666,6 +2653,11 @@ _ssl__SSLSocket_sendfile_impl(PySSLSocket *self, int fd, Py_off_t offset, | |||||
| Py_END_ALLOW_THREADS; | ||||||
| _PySSL_FIX_ERRNO; | ||||||
|
|
||||||
| exc = PyErr_GetRaisedException(); | ||||||
| if (exc != NULL) { | ||||||
| break; | ||||||
| } | ||||||
|
|
||||||
| if (PyErr_CheckSignals()) { | ||||||
| goto error; | ||||||
| } | ||||||
|
|
@@ -2715,15 +2707,18 @@ _ssl__SSLSocket_sendfile_impl(PySSLSocket *self, int fd, Py_off_t offset, | |||||
| } | ||||||
| Py_XDECREF(sock); | ||||||
| if (retval < 0) { | ||||||
| return PySSL_SetError(self, err, __FILE__, __LINE__); | ||||||
| return PySSL_SetError(self, err, exc, __FILE__, __LINE__); | ||||||
| } | ||||||
| if (PySSL_ChainExceptions(self) < 0) { | ||||||
| if (exc != NULL) { | ||||||
| PyErr_SetRaisedException(exc); | ||||||
| return NULL; | ||||||
| } | ||||||
| return PyLong_FromSize_t(retval); | ||||||
| error: | ||||||
| Py_XDECREF(sock); | ||||||
| (void)PySSL_ChainExceptions(self); | ||||||
| if (exc != NULL) { | ||||||
| _PyErr_ChainExceptions1(exc); | ||||||
| } | ||||||
| return NULL; | ||||||
| } | ||||||
| #endif /* BIO_get_ktls_send */ | ||||||
|
|
@@ -2747,6 +2742,7 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b) | |||||
| int retval; | ||||||
| int sockstate; | ||||||
| _PySSLError err; | ||||||
| PyObject *exc = NULL; | ||||||
| int nonblocking; | ||||||
| PySocketSockObject *sock = GET_SOCKET(self); | ||||||
| PyTime_t timeout, deadline = 0; | ||||||
|
|
@@ -2797,6 +2793,11 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b) | |||||
| Py_END_ALLOW_THREADS; | ||||||
| _PySSL_FIX_ERRNO; | ||||||
|
|
||||||
| exc = PyErr_GetRaisedException(); | ||||||
| if (exc != NULL) { | ||||||
| break; | ||||||
| } | ||||||
|
|
||||||
| if (PyErr_CheckSignals()) | ||||||
| goto error; | ||||||
|
|
||||||
|
|
@@ -2828,13 +2829,14 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b) | |||||
|
|
||||||
| Py_XDECREF(sock); | ||||||
| if (retval == 0) | ||||||
| return PySSL_SetError(self, err, __FILE__, __LINE__); | ||||||
| if (PySSL_ChainExceptions(self) < 0) | ||||||
| return PySSL_SetError(self, err, exc, __FILE__, __LINE__); | ||||||
| if (exc != NULL) { | ||||||
| PyErr_SetRaisedException(exc); | ||||||
| return NULL; | ||||||
| } | ||||||
| return PyLong_FromSize_t(count); | ||||||
| error: | ||||||
| Py_XDECREF(sock); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might add: |
||||||
| PySSL_ChainExceptions(self); | ||||||
| return NULL; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -2860,7 +2862,7 @@ _ssl__SSLSocket_pending_impl(PySSLSocket *self) | |||||
| _PySSL_FIX_ERRNO; | ||||||
|
|
||||||
| if (count < 0) | ||||||
| return PySSL_SetError(self, err, __FILE__, __LINE__); | ||||||
| return PySSL_SetError(self, err, NULL, __FILE__, __LINE__); | ||||||
| else | ||||||
| return PyLong_FromLong(count); | ||||||
| } | ||||||
|
|
@@ -2888,6 +2890,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len, | |||||
| int retval; | ||||||
| int sockstate; | ||||||
| _PySSLError err; | ||||||
| PyObject *exc; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with other functions:
Suggested change
|
||||||
| int nonblocking; | ||||||
| PySocketSockObject *sock = GET_SOCKET(self); | ||||||
| PyTime_t timeout, deadline = 0; | ||||||
|
|
@@ -2955,6 +2958,11 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len, | |||||
| Py_END_ALLOW_THREADS; | ||||||
| _PySSL_FIX_ERRNO; | ||||||
|
|
||||||
| exc = PyErr_GetRaisedException(); | ||||||
| if (exc != NULL) { | ||||||
| break; | ||||||
| } | ||||||
|
|
||||||
| if (PyErr_CheckSignals()) | ||||||
| goto error; | ||||||
|
|
||||||
|
|
@@ -2986,11 +2994,13 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len, | |||||
| err.ssl == SSL_ERROR_WANT_WRITE); | ||||||
|
|
||||||
| if (retval == 0) { | ||||||
| PySSL_SetError(self, err, __FILE__, __LINE__); | ||||||
| PySSL_SetError(self, err, exc, __FILE__, __LINE__); | ||||||
| goto error; | ||||||
| } | ||||||
| if (self->exc != NULL) | ||||||
| else if (exc != NULL) { | ||||||
| PyErr_SetRaisedException(exc); | ||||||
| goto error; | ||||||
| } | ||||||
|
|
||||||
| done: | ||||||
| Py_XDECREF(sock); | ||||||
|
|
@@ -3002,7 +3012,6 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len, | |||||
| } | ||||||
|
|
||||||
| error: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might add: |
||||||
| PySSL_ChainExceptions(self); | ||||||
| Py_XDECREF(sock); | ||||||
| if (!group_right_1) { | ||||||
| PyBytesWriter_Discard(writer); | ||||||
|
|
@@ -3022,6 +3031,7 @@ _ssl__SSLSocket_shutdown_impl(PySSLSocket *self) | |||||
| /*[clinic end generated code: output=ca1aa7ed9d25ca42 input=98d9635cd4e16514]*/ | ||||||
| { | ||||||
| _PySSLError err; | ||||||
| PyObject *exc = NULL; | ||||||
| int sockstate, nonblocking, ret; | ||||||
| int zeros = 0; | ||||||
| PySocketSockObject *sock = GET_SOCKET(self); | ||||||
|
|
@@ -3067,6 +3077,11 @@ _ssl__SSLSocket_shutdown_impl(PySSLSocket *self) | |||||
| Py_END_ALLOW_THREADS; | ||||||
| _PySSL_FIX_ERRNO; | ||||||
|
|
||||||
| exc = PyErr_GetRaisedException(); | ||||||
| if (exc != NULL) { | ||||||
| break; | ||||||
| } | ||||||
|
|
||||||
| /* If err == 1, a secure shutdown with SSL_shutdown() is complete */ | ||||||
| if (ret > 0) | ||||||
| break; | ||||||
|
|
@@ -3113,11 +3128,14 @@ _ssl__SSLSocket_shutdown_impl(PySSLSocket *self) | |||||
| } | ||||||
| if (ret < 0) { | ||||||
| Py_XDECREF(sock); | ||||||
| PySSL_SetError(self, err, __FILE__, __LINE__); | ||||||
| PySSL_SetError(self, err, exc, __FILE__, __LINE__); | ||||||
| return NULL; | ||||||
| } | ||||||
| else if (exc != NULL) { | ||||||
| Py_XDECREF(sock); | ||||||
picnixz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| PyErr_SetRaisedException(exc); | ||||||
| return NULL; | ||||||
| } | ||||||
| if (self->exc != NULL) | ||||||
| goto error; | ||||||
| if (sock) | ||||||
| /* It's already INCREF'ed */ | ||||||
| return (PyObject *) sock; | ||||||
|
|
@@ -3126,7 +3144,6 @@ _ssl__SSLSocket_shutdown_impl(PySSLSocket *self) | |||||
|
|
||||||
| error: | ||||||
| Py_XDECREF(sock); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might add: |
||||||
| PySSL_ChainExceptions(self); | ||||||
| return NULL; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -3335,7 +3352,6 @@ static PyType_Slot PySSLSocket_slots[] = { | |||||
| {Py_tp_getset, ssl_getsetlist}, | ||||||
| {Py_tp_dealloc, PySSL_dealloc}, | ||||||
| {Py_tp_traverse, PySSL_traverse}, | ||||||
| {Py_tp_clear, PySSL_clear}, | ||||||
| {0, 0}, | ||||||
| }; | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.