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
Assume (and then assert, a bit too late) that left is of the right type
  • Loading branch information
encukou committed Mar 5, 2025
commit 62cfadaeeb6d753e95e725ee9872dbd1d6600128
11 changes: 6 additions & 5 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5534,10 +5534,12 @@ PySSLSession_richcompare(PyObject *left, PyObject *right, int op)
}

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

if (!Py_IS_TYPE(left, sesstype) || !Py_IS_TYPE(right, sesstype)) {
PySSLSession *self = PySSLSession_CAST(left);
PyTypeObject *sesstype = Py_TYPE(self);
assert(sesstype == self->ctx->state->PySSLSession_Type);

if (!Py_IS_TYPE(right, sesstype)) {
Py_RETURN_NOTIMPLEMENTED;
}

Expand All @@ -5546,8 +5548,7 @@ PySSLSession_richcompare(PyObject *left, PyObject *right, int op)
} else {
const unsigned char *left_id, *right_id;
unsigned int left_len, right_len;
left_id = SSL_SESSION_get_id(((PySSLSession *)left)->session,
&left_len);
left_id = SSL_SESSION_get_id(self->session, &left_len);
right_id = SSL_SESSION_get_id(((PySSLSession *)right)->session,
&right_len);
if (left_len == right_len) {
Expand Down
Loading
0