From b97322e589f3e33fdd734950a561f95ce4b59cb9 Mon Sep 17 00:00:00 2001 From: Fidget-Spinner <28750310+Fidget-Spinner@users.noreply.github.com> Date: Thu, 28 Oct 2021 22:37:22 +0800 Subject: [PATCH 1/2] Add recursive checks for `CALL_FUNCTION_BUILTIN_O` --- Python/ceval.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Python/ceval.c b/Python/ceval.c index 4ac0b53dd6e466..09bd931ba56b97 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4742,8 +4742,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr STAT_INC(CALL_FUNCTION, hit); PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable); + if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) { + goto error; + } PyObject *arg = POP(); PyObject *res = cfunc(PyCFunction_GET_SELF(callable), arg); + _Py_LeaveRecursiveCall(tstate); assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL)); /* Clear the stack of the function object. */ From afee076bf9eeebefb74b5a5dc14cd0ee3efffb12 Mon Sep 17 00:00:00 2001 From: Fidget-Spinner <28750310+Fidget-Spinner@users.noreply.github.com> Date: Thu, 28 Oct 2021 22:39:24 +0800 Subject: [PATCH 2/2] add comment --- Python/ceval.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Python/ceval.c b/Python/ceval.c index 09bd931ba56b97..d52ca9c65db222 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4742,6 +4742,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr STAT_INC(CALL_FUNCTION, hit); PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable); + // This is slower but CPython promises to check all non-vectorcall + // function calls. if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) { goto error; }