8000 gh-111178: fix UBSan failures in `Modules/_ssl.c` by picnixz · Pull Request #130719 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures in Modules/_ssl.c #130719

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 17, 2025
Prev Previous commit
Next Next commit
fix UBSan failures for PySSLSession
  • Loading branch information
picnixz committed Feb 8, 2025
commit d734c1e8cb8258ff27b25f28f1e3d098de1bda30
14 changes: 10 additions & 4 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ typedef struct {
PySSLContext *ctx;
} PySSLSession;

#define PySSLSession_CAST(op) ((PySSLSession *)(op))

static inline _PySSLError _PySSL_errno(int failed, const SSL *ssl, int retcode)
{
_PySSLError err = { 0 };
Expand Down Expand Up @@ -5509,8 +5511,9 @@ static PyType_Spec PySSLMemoryBIO_spec = {
*/

static void
PySSLSession_dealloc(PySSLSession *self)
PySSLSession_dealloc(PyObject *op)
{
PySSLSession *self = PySSLSession_CAST(op);
PyTypeObject *tp = Py_TYPE(self);
/* bpo-31095: UnTrack is needed before calling any callbacks */
PyObject_GC_UnTrack(self);
Expand All @@ -5531,7 +5534,8 @@ PySSLSession_richcompare(PyObject *left, PyObject *right, int op)
}

int result;
PyTypeObject *sesstype = ((PySSLSession*)left)->ctx->state->PySSLSession_Type;
_sslmodulestate *state = get_state_obj(left);
PyTypeObject *sesstype = state->PySSLSession_Type;

if (!Py_IS_TYPE(left, sesstype) || !Py_IS_TYPE(right, sesstype)) {
Py_RETURN_NOTIMPLEMENTED;
Expand Down Expand Up @@ -5581,16 +5585,18 @@ PySSLSession_richcompare(PyObject *left, PyObject *right, int op)
}

static int
PySSLSession_traverse(PySSLSession *self, visitproc visit, void *arg)
PySSLSession_traverse(PyObject *op, visitproc visit, void *arg)
{
PySSLSession *self = PySSLSession_CAST(op);
Py_VISIT(self->ctx);
Py_VISIT(Py_TYPE(self));
return 0;
}

static int
PySSLSession_clear(PySSLSession *self)
PySSLSession_clear(PyObject *op)
{
PySSLSession *self = PySSLSession_CAST(op);
Py_CLEAR(self->ctx);
return 0;
}
Expand Down
0