Skip to content
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
align naming convention
  • Loading branch information
picnixz committed Jan 14, 2025
commit 6c2ef080440e8ad285e40be8e0b45822811358c2
38 changes: 19 additions & 19 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ get_exc_state(void)
*/

static inline PyBaseExceptionObject *
_PyBaseExceptionObject_cast(PyObject *exc)
_PyBaseExceptionObject_CAST(PyObject *exc)
{
assert(PyExceptionInstance_Check(exc));
return (PyBaseExceptionObject *)exc;
Expand Down Expand Up @@ -85,7 +85,7 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
BaseException_init(PyObject *op, PyObject *args, PyObject *kwds)
{
PyBaseExceptionObject *self = _PyBaseExceptionObject_cast(op);
PyBaseExceptionObject *self = _PyBaseExceptionObject_CAST(op);
if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds))
return -1;

Expand Down Expand Up @@ -130,7 +130,7 @@ BaseException_vectorcall(PyObject *type_obj, PyObject * const*args,
static int
BaseException_clear(PyObject *op)
{
PyBaseExceptionObject *self = _PyBaseExceptionObject_cast(op);
PyBaseExceptionObject *self = _PyBaseExceptionObject_CAST(op);
Py_CLEAR(self->dict);
Py_CLEAR(self->args);
Py_CLEAR(self->notes);
Expand All @@ -143,7 +143,7 @@ BaseException_clear(PyObject *op)
static void
BaseException_dealloc(PyObject *op)
{
PyBaseExceptionObject *self = _PyBaseExceptionObject_cast(op);
PyBaseExceptionObject *self = _PyBaseExceptionObject_CAST(op);
PyObject_GC_UnTrack(self);
// bpo-44348: The trashcan mechanism prevents stack overflow when deleting
// long chains of exceptions. For example, exceptions can be chained
Expand All @@ -157,7 +157,7 @@ BaseException_dealloc(PyObject *op)
static int
BaseException_traverse(PyObject *op, visitproc visit, void *arg)
{
PyBaseExceptionObject *self = _PyBaseExceptionObject_cast(op);
PyBaseExceptionObject *self = _PyBaseExceptionObject_CAST(op);
Py_VISIT(self->dict);
Py_VISIT(self->args);
Py_VISIT(self->notes);
Expand All @@ -170,7 +170,7 @@ BaseException_traverse(PyObject *op, visitproc visit, void *arg)
static PyObject *
BaseException_str(PyObject *op)
{
PyBaseExceptionObject *self = _PyBaseExceptionObject_cast(op);
PyBaseExceptionObject *self = _PyBaseExceptionObject_CAST(op);

PyObject *res;
Py_BEGIN_CRITICAL_SECTION(self);
Expand All @@ -193,7 +193,7 @@ static PyObject *
BaseException_repr(PyObject *op)
{

PyBaseExceptionObject *self = _PyBaseExceptionObject_cast(op);
PyBaseExceptionObject *self = _PyBaseExceptionObject_CAST(op);

PyObject *res;
Py_BEGIN_CRITICAL_SECTION(self);
Expand Down Expand Up @@ -520,7 +520,7 @@ PyException_GetTraceback(PyObject *self)
{
PyObject *traceback;
Py_BEGIN_CRITICAL_SECTION(self);
traceback = Py_XNewRef(_PyBaseExceptionObject_cast(self)->traceback);
traceback = Py_XNewRef(_PyBaseExceptionObject_CAST(self)->traceback);
Py_END_CRITICAL_SECTION();
return traceback;
}
Expand All @@ -531,7 +531,7 @@ PyException_SetTraceback(PyObject *self, PyObject *tb)
{
int res;
Py_BEGIN_CRITICAL_SECTION(self);
res = BaseException___traceback___set_impl(_PyBaseExceptionObject_cast(self), tb);
res = BaseException___traceback___set_impl(_PyBaseExceptionObject_CAST(self), tb);
Py_END_CRITICAL_SECTION();
return res;
}
Expand All @@ -541,7 +541,7 @@ PyException_GetCause(PyObject *self)
{
PyObject *cause;
Py_BEGIN_CRITICAL_SECTION(self);
cause = Py_XNewRef(_PyBaseExceptionObject_cast(self)->cause);
cause = Py_XNewRef(_PyBaseExceptionObject_CAST(self)->cause);
Py_END_CRITICAL_SECTION();
return cause;
}
Expand All @@ -551,7 +551,7 @@ void
PyException_SetCause(PyObject *self, PyObject *cause)
{
Py_BEGIN_CRITICAL_SECTION(self);
PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self);
PyBaseExceptionObject *base_self = _PyBaseExceptionObject_CAST(self);
base_self->suppress_context = 1;
Py_XSETREF(base_self->cause, cause);
Py_END_CRITICAL_SECTION();
Expand All @@ -562,7 +562,7 @@ PyException_GetContext(PyObject *self)
{
PyObject *context;
Py_BEGIN_CRITICAL_SECTION(self);
context = Py_XNewRef(_PyBaseExceptionObject_cast(self)->context);
context = Py_XNewRef(_PyBaseExceptionObject_CAST(self)->context);
Py_END_CRITICAL_SECTION();
return context;
}
Expand All @@ -572,7 +572,7 @@ void
PyException_SetContext(PyObject *self, PyObject *context)
{
Py_BEGIN_CRITICAL_SECTION(self);
Py_XSETREF(_PyBaseExceptionObject_cast(self)->context, context);
Py_XSETREF(_PyBaseExceptionObject_CAST(self)->context, context);
Py_END_CRITICAL_SECTION();
}

Expand All @@ -581,7 +581,7 @@ PyException_GetArgs(PyObject *self)
{
PyObject *args;
Py_BEGIN_CRITICAL_SECTION(self);
args = Py_NewRef(_PyBaseExceptionObject_cast(self)->args);
args = Py_NewRef(_PyBaseExceptionObject_CAST(self)->args);
Py_END_CRITICAL_SECTION();
return args;
}
Expand All @@ -591,7 +591,7 @@ PyException_SetArgs(PyObject *self, PyObject *args)
{
Py_BEGIN_CRITICAL_SECTION(self);
Py_INCREF(args);
Py_XSETREF(_PyBaseExceptionObject_cast(self)->args, args);
Py_XSETREF(_PyBaseExceptionObject_CAST(self)->args, args);
Py_END_CRITICAL_SECTION();
}

Expand Down Expand Up @@ -1829,7 +1829,7 @@ ImportError_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
PyObject *state = ImportError_getstate(self);
if (state == NULL)
return NULL;
PyBaseExceptionObject *exc = _PyBaseExceptionObject_cast(self);
PyBaseExceptionObject *exc = _PyBaseExceptionObject_CAST(self);
if (state == Py_None)
res = PyTuple_Pack(2, Py_TYPE(self), exc->args);
else
Expand Down Expand Up @@ -2850,7 +2850,7 @@ KeyError_str(PyObject *op)
string, that string will be displayed in quotes. Too bad.
If args is anything else, use the default BaseException__str__().
*/
PyBaseExceptionObject *self = _PyBaseExceptionObject_cast(op);
PyBaseExceptionObject *self = _PyBaseExceptionObject_CAST(op);
if (PyTuple_GET_SIZE(self->args) == 1) {
return PyObject_Repr(PyTuple_GET_ITEM(self->args, 0));
}
Expand Down Expand Up @@ -3863,7 +3863,7 @@ _PyErr_NoMemory(PyThreadState *tstate)
static void
MemoryError_dealloc(PyObject *op)
{
PyBaseExceptionObject *self = _PyBaseExceptionObject_cast(op);
PyBaseExceptionObject *self = _PyBaseExceptionObject_CAST(op);
_PyObject_GC_UNTRACK(self);

(void)BaseException_clear(op);
Expand Down Expand Up @@ -4347,7 +4347,7 @@ _PyException_AddNote(PyObject *exc, PyObject *note)
Py_TYPE(exc)->tp_name);
return -1;
}
PyObject *r = BaseException_add_note(_PyBaseExceptionObject_cast(exc), note);
PyObject *r = BaseException_add_note(_PyBaseExceptionObject_CAST(exc), note);
int res = r == NULL ? -1 : 0;
Py_XDECREF(r);
return res;
Expand Down