[3.13] gh-126220: Fix crash on calls to _lsprof.Profiler methods with 0 args (backportable) (GH-126271) (#126310)

gh-126220: Fix crash on calls to `_lsprof.Profiler` methods with 0 args (backportable) (GH-126271)
(cherry picked from commit 28b148fb32)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
Miss Islington (bot) 2024-11-01 23:24:06 +01:00 committed by GitHub
parent 5c04055082
commit 1b9710c571
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 0 deletions

View file

@ -608,6 +608,12 @@ setBuiltins(ProfilerObject *pObj, int nvalue)
PyObject* pystart_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size)
{
if (size < 2) {
PyErr_Format(PyExc_TypeError,
"_pystart_callback expected 2 arguments, got %zd",
size);
return NULL;
}
PyObject* code = args[0];
ptrace_enter_call((PyObject*)self, (void *)code, (PyObject *)code);
@ -616,6 +622,12 @@ PyObject* pystart_callback(ProfilerObject* self, PyObject *const *args, Py_ssize
PyObject* pyreturn_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size)
{
if (size < 3) {
PyErr_Format(PyExc_TypeError,
"_pyreturn_callback expected 3 arguments, got %zd",
size);
return NULL;
}
PyObject* code = args[0];
ptrace_leave_call((PyObject*)self, (void *)code);
@ -651,6 +663,12 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObje
PyObject* ccall_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size)
{
if (size < 4) {
PyErr_Format(PyExc_TypeError,
"_ccall_callback expected 4 arguments, got %zd",
size);
return NULL;
}
if (self->flags & POF_BUILTINS) {
PyObject* callable = args[2];
PyObject* self_arg = args[3];
@ -669,6 +687,12 @@ PyObject* ccall_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t
PyObject* creturn_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size)
{
if (size < 4) {
PyErr_Format(PyExc_TypeError,
"_creturn_callback expected 4 arguments, got %zd",
size);
return NULL;
}
if (self->flags & POF_BUILTINS) {
PyObject* callable = args[2];
PyObject* self_arg = args[3];