Skip to content
Prev Previous commit
Next Next commit
Do not use _ + capital letter in cast macros as it is also UB.
  • Loading branch information
picnixz committed Feb 8, 2025
commit fe9f918a769c95edbfd9e6ed5ea358bd2c443e24
10 changes: 5 additions & 5 deletions Modules/_ssl/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ _x509name_print(_sslmodulestate *state, X509_NAME *name, int indent, unsigned lo
* PySSLCertificate_Type
*/

#define _PySSLCertificate_CAST(op) ((PySSLCertificate *)(op))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't thinkt that this change is useful.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I myself did the change and I at that time put an underscore. But considering I used the convention "objectname+_CAST" for the series of PR and that I amended some changes I've done recently I think we can refactor this one as well (if the code is however not by me and/or is older, I can revert that change)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: it's something I've changed last month, and I thought I fixed all the UBSan issues in the SSL module but this wasn't the case. I can revert it if you don't want this additional diff.

#define PySSLCertificate_CAST(op) ((PySSLCertificate *)(op))

static PyObject *
certificate_repr(PyObject *op)
{
PyObject *osubject, *result;
PySSLCertificate *self = _PySSLCertificate_CAST(op);
PySSLCertificate *self = PySSLCertificate_CAST(op);

/* subject string is ASCII encoded, UTF-8 chars are quoted */
osubject = _x509name_print(
Expand All @@ -181,7 +181,7 @@ certificate_repr(PyObject *op)
static Py_hash_t
certificate_hash(PyObject *op)
{
PySSLCertificate *self = _PySSLCertificate_CAST(op);
PySSLCertificate *self = PySSLCertificate_CAST(op);
if (self->hash == (Py_hash_t)-1) {
unsigned long hash;
hash = X509_subject_name_hash(self->cert);
Expand All @@ -198,7 +198,7 @@ static PyObject *
certificate_richcompare(PyObject *lhs, PyObject *rhs, int op)
{
int cmp;
PySSLCertificate *self = _PySSLCertificate_CAST(lhs);
PySSLCertificate *self = PySSLCertificate_CAST(lhs);
_sslmodulestate *state = get_state_cert(self);

if (Py_TYPE(rhs) != state->PySSLCertificate_Type) {
Expand All @@ -219,7 +219,7 @@ certificate_richcompare(PyObject *lhs, PyObject *rhs, int op)
static void
certificate_dealloc(PyObject *op)
{
PySSLCertificate *self = _PySSLCertificate_CAST(op);
PySSLCertificate *self = PySSLCertificate_CAST(op);
PyTypeObject *tp = Py_TYPE(self);
X509_free(self->cert);
(void)Py_TYPE(self)->tp_free(self);
Expand Down