mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
[3.12] GH-108390: Prevent non-local events being set with sys.monitoring.set_local_events()
(GH-108420) (#108899)
* GH-108390: Prevent non-local events being set with `sys.monitoring.set_local_events()` (GH-108420) * Restore generated objects * Restore size of monitoring arrays in code object for 3.12 ABI compatibility. * Update ABI file
This commit is contained in:
parent
5121faabd1
commit
7ee021f999
8 changed files with 3101 additions and 3001 deletions
|
@ -2021,28 +2021,30 @@ do_monitor_exc(PyThreadState *tstate, _PyInterpreterFrame *frame,
|
|||
return err;
|
||||
}
|
||||
|
||||
static inline int
|
||||
no_tools_for_event(PyThreadState *tstate, _PyInterpreterFrame *frame, int event)
|
||||
static inline bool
|
||||
no_tools_for_global_event(PyThreadState *tstate, int event)
|
||||
{
|
||||
return tstate->interp->monitors.tools[event] == 0;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
no_tools_for_local_event(PyThreadState *tstate, _PyInterpreterFrame *frame, int event)
|
||||
{
|
||||
assert(event < _PY_MONITORING_LOCAL_EVENTS);
|
||||
_PyCoMonitoringData *data = frame->f_code->_co_monitoring;
|
||||
if (data) {
|
||||
if (data->active_monitors.tools[event] == 0) {
|
||||
return 1;
|
||||
}
|
||||
return data->active_monitors.tools[event] == 0;
|
||||
}
|
||||
else {
|
||||
if (tstate->interp->monitors.tools[event] == 0) {
|
||||
return 1;
|
||||
}
|
||||
return no_tools_for_global_event(tstate, event);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
monitor_raise(PyThreadState *tstate, _PyInterpreterFrame *frame,
|
||||
_Py_CODEUNIT *instr)
|
||||
{
|
||||
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_RAISE)) {
|
||||
if (no_tools_for_global_event(tstate, PY_MONITORING_EVENT_RAISE)) {
|
||||
return;
|
||||
}
|
||||
do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_RAISE);
|
||||
|
@ -2052,7 +2054,7 @@ static void
|
|||
monitor_reraise(PyThreadState *tstate, _PyInterpreterFrame *frame,
|
||||
_Py_CODEUNIT *instr)
|
||||
{
|
||||
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_RERAISE)) {
|
||||
if (no_tools_for_global_event(tstate, PY_MONITORING_EVENT_RERAISE)) {
|
||||
return;
|
||||
}
|
||||
do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_RERAISE);
|
||||
|
@ -2062,7 +2064,7 @@ static int
|
|||
monitor_stop_iteration(PyThreadState *tstate, _PyInterpreterFrame *frame,
|
||||
_Py_CODEUNIT *instr)
|
||||
{
|
||||
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_STOP_ITERATION)) {
|
||||
if (no_tools_for_local_event(tstate, frame, PY_MONITORING_EVENT_STOP_ITERATION)) {
|
||||
return 0;
|
||||
}
|
||||
return do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_STOP_ITERATION);
|
||||
|
@ -2073,7 +2075,7 @@ monitor_unwind(PyThreadState *tstate,
|
|||
_PyInterpreterFrame *frame,
|
||||
_Py_CODEUNIT *instr)
|
||||
{
|
||||
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_PY_UNWIND)) {
|
||||
if (no_tools_for_global_event(tstate, PY_MONITORING_EVENT_PY_UNWIND)) {
|
||||
return;
|
||||
}
|
||||
do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_PY_UNWIND);
|
||||
|
@ -2085,7 +2087,7 @@ monitor_handled(PyThreadState *tstate,
|
|||
_PyInterpreterFrame *frame,
|
||||
_Py_CODEUNIT *instr, PyObject *exc)
|
||||
{
|
||||
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_EXCEPTION_HANDLED)) {
|
||||
if (no_tools_for_global_event(tstate, PY_MONITORING_EVENT_EXCEPTION_HANDLED)) {
|
||||
return 0;
|
||||
}
|
||||
return _Py_call_instrumentation_arg(tstate, PY_MONITORING_EVENT_EXCEPTION_HANDLED, frame, instr, exc);
|
||||
|
@ -2096,7 +2098,7 @@ monitor_throw(PyThreadState *tstate,
|
|||
_PyInterpreterFrame *frame,
|
||||
_Py_CODEUNIT *instr)
|
||||
{
|
||||
if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_PY_THROW)) {
|
||||
if (no_tools_for_global_event(tstate, PY_MONITORING_EVENT_PY_THROW)) {
|
||||
return;
|
||||
}
|
||||
do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_PY_THROW);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue