8000 gh-111178: fix UBSan failures in `Objects/exceptions.c` by picnixz · Pull Request #128154 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures in Objects/exceptions.c #128154

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 25 commits into from
Feb 17, 2025
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2683a25
fix UBSan failures for `PyBaseExceptionObject`
picnixz Dec 21, 2024
3f1196b
fix UBSan failures for `PyStopIterationObject`
picnixz Dec 21, 2024
1886b07
fix UBSan failures for `PySystemExitObject`
picnixz Dec 21, 2024
3df93a5
fix UBSan failures for `PyImportErrorObject`
picnixz Dec 21, 2024
96f97a5
fix UBSan failures for `PyOSErrorObject`
picnixz Dec 21, 2024
09514a9
fix UBSan failures for `PyNameErrorObject`
picnixz Dec 21, 2024
9d3c8b8
fix UBSan failures for `PyAttributeErrorObject`
picnixz Dec 21, 2024
2640a34
fix UBSan failures for `PySyntaxErrorObject`
picnixz Dec 21, 2024
150f34e
fix UBSan failures for `KeyError`
picnixz Dec 21, 2024
11d9e31
remove un-necessary casts for `UnicodeError*`
picnixz Dec 21, 2024
96430d9
remove un-necessary casts for `MemoryError`
picnixz Dec 21, 2024
0437291
fix UBSan failures for `PyBaseExceptionGroupObject`
picnixz Dec 21, 2024
d17a9b4
unify naming for cast functions
picnixz Dec 21, 2024
0d2434e
Merge remote-tracking branch 'upstream/main' into fix/ubsan/exception…
picnixz Jan 14, 2025
793196d
fixup
picnixz Jan 14, 2025
6abf1d8
fixup
picnixz Jan 14, 2025
6c2ef08
align naming convention
picnixz Jan 14, 2025
96f2d2d
remove redundant casts
picnixz Jan 16, 2025
0cd116b
Merge branch 'main' into fix/ubsan/exceptions-111178
picnixz Jan 18, 2025
248f195
Merge remote-tracking branch 'upstream/main' into fix/ubsan/exception…
picnixz Jan 25, 2025
e4daf11
remove un-necessary cast
picnixz Feb 6, 2025
565edab
Merge branch 'main' into fix/ubsan/exceptions-111178
picnixz Feb 7, 2025
122c914
Do not use `_` + capital letter in cast macros as it is also UB.
picnixz Feb 8, 2025
7906e3b
Do not use `_` + capital letter in cast macros as it is also UB.
picnixz Feb 8, 2025
8862b83
Merge branch 'main' into fix/ubsan/exceptions-111178
picnixz Feb 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix UBSan failures for PyBaseExceptionGroupObject
  • Loading branch information
picnixz committed Dec 21, 2024
commit 0437291c052f4799184c13481083e35c7fd99155
41 changes: 21 additions & 20 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ ComplexExtendsException(PyExc_BaseException, SystemExit, SystemExit,


static inline PyBaseExceptionGroupObject*
_PyBaseExceptionGroupObject_cast(PyObject *exc)
_PyBaseExceptionGroup_CAST(PyObject *exc)
{
assert(_PyBaseExceptionGroup_Check(exc));
return (PyBaseExceptionGroupObject *)exc;
Expand Down Expand Up @@ -865,7 +865,7 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
cls = (PyTypeObject*)PyExc_BaseExceptionGroup;
}
PyBaseExceptionGroupObject *self =
_PyBaseExceptionGroupObject_cast(BaseException_new(cls, args, kwds));
_PyBaseExceptionGroup_CAST(BaseException_new(cls, args, kwds));
if (!self) {
goto error;
}
Expand Down Expand Up @@ -896,46 +896,47 @@ _PyExc_CreateExceptionGroup(const char *msg_str, PyObject *excs)
}

static int
BaseExceptionGroup_init(PyBaseExceptionGroupObject *self,
PyObject *args, PyObject *kwds)
BaseExceptionGroup_init(PyObject *self, PyObject *args, PyObject *kwds)
{
if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) {
return -1;
}
if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) {
if (BaseException_init(self, args, kwds) == -1) {
return -1;
}
return 0;
}

static int
BaseExceptionGroup_clear(PyBaseExceptionGroupObject *self)
BaseExceptionGroup_clear(PyObject *op)
{
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroup_CAST(op);
Py_CLEAR(self->msg);
Py_CLEAR(self->excs);
return BaseException_clear((PyBaseExceptionObject *)self);
return BaseException_clear(op);
}

static void
BaseExceptionGroup_dealloc(PyBaseExceptionGroupObject *self)
BaseExceptionGroup_dealloc(PyObject *self)
{
_PyObject_GC_UNTRACK(self);
BaseExceptionGroup_clear(self);
Py_TYPE(self)->tp_free((PyObject *)self);
(void)BaseExceptionGroup_clear(self);
Py_TYPE(self)->tp_free(self);
}

static int
BaseExceptionGroup_traverse(PyBaseExceptionGroupObject *self,
visitproc visit, void *arg)
BaseExceptionGroup_traverse(PyObject *op, visitproc visit, void *arg)
{
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroup_CAST(op);
Py_VISIT(self->msg);
Py_VISIT(self->excs);
return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
return BaseException_traverse(op, visit, arg);
}

static PyObject *
BaseExceptionGroup_str(PyBaseExceptionGroupObject *self)
BaseExceptionGroup_str(PyObject *op)
{
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroup_CAST(op);
assert(self->msg);
assert(PyUnicode_Check(self->msg));

Expand All @@ -949,7 +950,7 @@ BaseExceptionGroup_str(PyBaseExceptionGroupObject *self)
static PyObject *
BaseExceptionGroup_derive(PyObject *self_, PyObject *excs)
{
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroupObject_cast(self_);
PyBaseExceptionGroupObject *self = _PyBaseExceptionGroup_CAST(self_);
PyObject *init_args = PyTuple_Pack(2, self->msg, excs);
if (!init_args) {
return NULL;
Expand Down Expand Up @@ -1162,7 +1163,7 @@ exceptiongroup_split_recursive(PyObject *exc,

/* Partial match */

PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroupObject_cast(exc);
PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroup_CAST(exc);
assert(PyTuple_CheckExact(eg->excs));
Py_ssize_t num_excs = PyTuple_Size(eg->excs);
if (num_excs < 0) {
Expand Down Expand Up @@ -1313,7 +1314,7 @@ collect_exception_group_leaf_ids(PyObject *exc, PyObject *leaf_ids)
Py_DECREF(exc_id);
return res;
}
PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroupObject_cast(exc);
PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroup_CAST(exc);
Py_ssize_t num_excs = PyTuple_GET_SIZE(eg->excs);
/* recursive calls */
for (Py_ssize_t i = 0; i < num_excs; i++) {
Expand Down Expand Up @@ -1545,9 +1546,9 @@ static PyMemberDef BaseExceptionGroup_members[] = {
static PyMethodDef BaseExceptionGroup_methods[] = {
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"derive", (PyCFunction)BaseExceptionGroup_derive, METH_O},
{"split", (PyCFunction)BaseExceptionGroup_split, METH_O},
{"subgroup", (PyCFunction)BaseExceptionGroup_subgroup, METH_O},
{"derive", BaseExceptionGroup_derive, METH_O},
{"split", BaseExceptionGroup_split, METH_O},
{"subgroup", BaseExceptionGroup_subgroup, METH_O},
{NULL}
};

Expand Down
0