8000 gh-111178: fix UBSan failures in `Modules/_interp*module.c` by picnixz · Pull Request #129779 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures in Modules/_interp*module.c #129779

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 10 commits into from
Feb 17, 2025
Merged
Prev Previous commit
Next Next commit
fix UBSan failures for XIBufferViewObject
  • Loading branch information
picnixz committed Jan 25, 2025
commit 7dad5529e4d6d532f3d0cb957d5b7a7225a2b6fd
14 changes: 9 additions & 5 deletions Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ typedef struct {
int64_t interpid;
} XIBufferViewObject;

#define _XIBufferViewObject_CAST(op) ((XIBufferViewObject *)(op))

static PyObject *
xibufferview_from_xid(PyTypeObject *cls, _PyXIData_t *data)
{
Expand All @@ -100,8 +102,9 @@ xibufferview_from_xid(PyTypeObject *cls, _PyXIData_t *data)
}

static void
xibufferview_dealloc(XIBufferViewObject *self)
xibufferview_dealloc(PyObject *op)
{
XIBufferViewObject *self = _XIBufferViewObject_CAST(op);
PyInterpreterState *interp = _PyInterpreterState_LookUpID(self->interpid);
/* If the interpreter is no longer alive then we have problems,
since other objects may be using the buffer still. */
Expand All @@ -124,20 +127,21 @@ xibufferview_dealloc(XIBufferViewObject *self)
}

static int
xibufferview_getbuf(XIBufferViewObject *self, Py_buffer *view, int flags)
xibufferview_getbuf(PyObject *op, Py_buffer *view, int flags)
{
/* Only PyMemoryView_FromObject() should ever call this,
via _memoryview_from_xid() below. */
XIBufferViewObject *self = _XIBufferViewObject_CAST(op);
*view = *self->view;
view->obj = (PyObject *)self;
view->obj = op;
// XXX Should we leave it alone?
view->internal = NULL;
return 0;
}

static PyType_Slot XIBufferViewType_slots[] = {
{Py_tp_dealloc, (destructor)xibufferview_dealloc},
{Py_bf_getbuffer, (getbufferproc)xibufferview_getbuf},
{Py_tp_dealloc, xibufferview_dealloc},
{Py_bf_getbuffer, xibufferview_getbuf},
// We don't bother with Py_bf_releasebuffer since we don't need it.
{0, NULL},
};
Expand Down
0