gh-111178: fix UBSan failures in Modules/_ssl.c (GH-130719)

* fix UBSan failures for `PySSLContext`, `PySSLSocket`, `PySSLMemoryBIO`, `PySSLSession`
This commit is contained in:
Bénédikt Tran 2025-03-17 16:25:28 +01:00 committed by GitHub
parent a45f25361d
commit e708ac8dd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 67 additions and 35 deletions

View file

@ -85,7 +85,9 @@ _PySSL_msg_callback(int write_p, int version, int content_type,
static PyObject *
_PySSLContext_get_msg_callback(PySSLContext *self, void *c) {
_PySSLContext_get_msg_callback(PyObject *op, void *Py_UNUSED(closure))
{
PySSLContext *self = PySSLContext_CAST(op);
if (self->msg_cb != NULL) {
return Py_NewRef(self->msg_cb);
} else {
@ -94,7 +96,10 @@ _PySSLContext_get_msg_callback(PySSLContext *self, void *c) {
}
static int
_PySSLContext_set_msg_callback(PySSLContext *self, PyObject *arg, void *c) {
_PySSLContext_set_msg_callback(PyObject *op, PyObject *arg,
void *Py_UNUSED(closure))
{
PySSLContext *self = PySSLContext_CAST(op);
Py_CLEAR(self->msg_cb);
if (arg == Py_None) {
SSL_CTX_set_msg_callback(self->ctx, NULL);
@ -153,7 +158,9 @@ _PySSL_keylog_callback(const SSL *ssl, const char *line)
}
static PyObject *
_PySSLContext_get_keylog_filename(PySSLContext *self, void *c) {
_PySSLContext_get_keylog_filename(PyObject *op, void *Py_UNUSED(closure))
{
PySSLContext *self = PySSLContext_CAST(op);
if (self->keylog_filename != NULL) {
return Py_NewRef(self->keylog_filename);
} else {
@ -162,7 +169,10 @@ _PySSLContext_get_keylog_filename(PySSLContext *self, void *c) {
}
static int
_PySSLContext_set_keylog_filename(PySSLContext *self, PyObject *arg, void *c) {
_PySSLContext_set_keylog_filename(PyObject *op, PyObject *arg,
void *Py_UNUSED(closure))
{
PySSLContext *self = PySSLContext_CAST(op);
FILE *fp;
/* Reset variables and callback first */
SSL_CTX_set_keylog_callback(self->ctx, NULL);