10000 gh-111178: fix UBSan failures in `Modules/selectmodule.c` by picnixz · Pull Request #129792 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures in Modules/selectmodule.c #129792

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 13 commits into from
Feb 24, 2025
Merged
Prev Previous commit
Next Next commit
fix UBSan failures for kqueue_queue_Object
  • Loading branch information
picnixz committed Feb 6, 2025
commit bfb9b81b90ce4e97f32b5ceafbd017121b59fc42
22 changes: 13 additions & 9 deletions Modules/selectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,8 @@ typedef struct kqueue_queue_Object {
SOCKET kqfd; /* kqueue control fd */
} kqueue_queue_Object;

#define kqueue_queue_Object_CAST(op) ((kqueue_queue_Object *)(op))

#if (SIZEOF_UINTPTR_T != SIZEOF_VOID_P)
# error uintptr_t does not match void *!
#elif (SIZEOF_UINTPTR_T == SIZEOF_LONG_LONG)
Expand Down Expand Up @@ -2192,10 +2194,11 @@ select_kqueue_impl(PyTypeObject *type)
}

static void
kqueue_queue_finalize(kqueue_queue_Object *self)
kqueue_queue_finalize(PyObject *op)
{
PyObject* error = PyErr_GetRaisedException();
kqueue_queue_internal_close(self);
kqueue_queue_Object *self = kqueue_queue_Object_CAST(op);
PyObject *error = PyErr_GetRaisedException();
(void)kqueue_queue_internal_close(self);
PyErr_SetRaisedException(error);
}

Expand All @@ -2220,13 +2223,14 @@ select_kqueue_close_impl(kqueue_queue_Object *self)
Py_RETURN_NONE;
}

static PyObject*
kqueue_queue_get_closed(kqueue_queue_Object *self, void *Py_UNUSED(ignored))
static PyObject *
kqueue_queue_get_closed(PyObject *op, void *Py_UNUSED(closure))
{
if (self->kqfd < 0)
kqueue_queue_Object *self = kqueue_queue_Object_CAST(op);
if (self->kqfd < 0) {
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
Py_RETURN_FALSE;
}

/*[clinic input]
Expand Down Expand Up @@ -2433,7 +2437,7 @@ select_kqueue_control_impl(kqueue_queue_Object *self, PyObject *changelist,
}

static PyGetSetDef kqueue_queue_getsetlist[] = {
{"closed", (getter)kqueue_queue_get_closed, NULL,
{"closed", kqueue_queue_get_closed, NULL,
"True if the kqueue handler is closed"},
{0},
};
Expand Down
0