Skip to content

Commit 62cfada

Browse files
committed
Assume (and then assert, a bit too late) that left is of the right type
1 parent 58d5d42 commit 62cfada

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Modules/_ssl.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5534,10 +5534,12 @@ PySSLSession_richcompare(PyObject *left, PyObject *right, int op)
55345534
}
55355535

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

5540-
if (!Py_IS_TYPE(left, sesstype) || !Py_IS_TYPE(right, sesstype)) {
5538+
PySSLSession *self = PySSLSession_CAST(left);
5539+
PyTypeObject *sesstype = Py_TYPE(self);
5540+
assert(sesstype == self->ctx->state->PySSLSession_Type);
5541+
5542+
if (!Py_IS_TYPE(right, sesstype)) {
55415543
Py_RETURN_NOTIMPLEMENTED;
55425544
}
55435545

@@ -5546,8 +5548,7 @@ PySSLSession_richcompare(PyObject *left, PyObject *right, int op)
55465548
} else {
55475549
const unsigned char *left_id, *right_id;
55485550
unsigned int left_len, right_len;
5549-
left_id = SSL_SESSION_get_id(((PySSLSession *)left)->session,
5550-
&left_len);
5551+
left_id = SSL_SESSION_get_id(self->session, &left_len);
55515552
right_id = SSL_SESSION_get_id(((PySSLSession *)right)->session,
55525553
&right_len);
55535554
if (left_len == right_len) {

0 commit comments

Comments
 (0)