Skip to content

Commit

Permalink
Assume (and then assert, a bit too late) that left is of the right type
Browse files Browse the repository at this point in the history
  • Loading branch information
encukou committed Mar 5, 2025
1 parent 58d5d42 commit 62cfada
Showing 1 changed file with 6 additions and 5 deletions.
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

0 comments on commit 62cfada

Please sign in to comment.