8000 gh-111178: fix UBSan failures for `Python/legacy_tracing.c` by picnixz · Pull Request #131611 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures for Python/legacy_tracing.c #131611

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 7 commits into from
Mar 24, 2025
Merged
Changes from 1 commit
Commits
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
Merge remote-tracking branch 'upstream/main' into fix/ubsan/sys-funcs…
…-111178
  • Loading branch information
picnixz committed Mar 23, 2025
commit 2a3fea59af6a20765598b2c3b5e55966777ffdef
42 changes: 22 additions & 20 deletions Python/legacy_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ call_trace_func(_PyLegacyEventHandler *self, PyObject *arg)

static PyObject *
sys_trace_exception_func(
PyObject *op, PyObject *const *args,
PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(callable);
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 3);
PyObject *exc = args[2];
Expand All @@ -217,43 +217,43 @@ sys_trace_exception_func(

static PyObject *
sys_trace_start(
PyObject *op, PyObject *const *args,
PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(callable);
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 2);
return call_trace_func(self, Py_None);
}

static PyObject *
sys_trace_throw(
PyObject *op, PyObject *const *args,
PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(callable);
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 3);
return call_trace_func(self, Py_None);
}

static PyObject *
sys_trace_unwind(
PyObject *op, PyObject *const *args,
PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(callable);
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 3);
return call_trace_func(self, NULL);
}

static PyObject *
sys_trace_return(
PyObject *op, PyObject *const *args,
PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(callable);
assert(!PyErr_Occurred());
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 3);
Expand All @@ -265,21 +265,21 @@ sys_trace_return(

static PyObject *
sys_trace_yield(
PyObject *op, PyObject *const *args,
PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(callable);
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 3);
return call_trace_func(self, args[2]);
}

static PyObject *
sys_trace_instruction_func(
PyObject *op, PyObject *const *args,
PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(callable);
assert(kwnames == NULL);
assert(PyVectorcall_NARGS(nargsf) == 2);
PyFrameObject *frame = PyEval_GetFrame();
Expand Down Expand Up @@ -329,10 +329,10 @@ trace_line(

static PyObject *
sys_trace_line_func(
PyObject *op, PyObject *const *args,
PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(callable);
assert(kwnames == NULL);
PyThreadState *tstate = _PyThreadState_GET();
if (tstate->c_tracefunc == NULL) {
Expand All @@ -356,10 +356,10 @@ sys_trace_line_func(
* Handle that case here */
static PyObject *
sys_trace_jump_func(
PyObject *op, PyObject *const *args,
PyObject *callable, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(callable);
assert(kwnames == NULL);
PyThreadState *tstate = _PyThreadState_GET();
if (tstate->c_tracefunc == NULL) {
Expand Down Expand Up @@ -532,7 +532,8 @@ setup_tracing(PyThreadState *tstate, Py_tracefunc func, PyObject *arg, PyObject
tstate->interp->sys_trace_initialized = true;
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
sys_trace_start, PyTrace_CALL,
PY_MONITORING_EVENT_PY_START, PY_MONITORING_EVENT_PY_RESUME)) {
PY_MONITORING_EVENT_PY_START,
PY_MONITORING_EVENT_PY_RESUME)) {
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
Expand All @@ -552,7 +553,8 @@ setup_tracing(PyThreadState *tstate, Py_tracefunc func, PyObject *arg, PyObject
}
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
sys_trace_exception_func, PyTrace_EXCEPTION,
PY_MONITORING_EVENT_RAISE, PY_MONITORING_EVENT_STOP_ITERATION)) {
PY_MONITORING_EVENT_RAISE,
PY_MONITORING_EVENT_STOP_ITERATION)) {
return -1;
}
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0