mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gh-124513: Check args in framelocalsproxy_new() (#124515)
Fix a crash in FrameLocalsProxy constructor: check the number of arguments.
This commit is contained in:
parent
0d9d56c4e4
commit
d6954b6421
3 changed files with 43 additions and 3 deletions
|
@ -310,14 +310,31 @@ framelocalsproxy_dealloc(PyObject *self)
|
|||
static PyObject *
|
||||
framelocalsproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
if (PyTuple_GET_SIZE(args) != 1) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"FrameLocalsProxy expected 1 argument, got %zd",
|
||||
PyTuple_GET_SIZE(args));
|
||||
return NULL;
|
||||
}
|
||||
PyObject *item = PyTuple_GET_ITEM(args, 0);
|
||||
|
||||
if (!PyFrame_Check(item)) {
|
||||
PyErr_Format(PyExc_TypeError, "expect frame, not %T", item);
|
||||
return NULL;
|
||||
}
|
||||
PyFrameObject *frame = (PyFrameObject*)item;
|
||||
|
||||
if (kwds != NULL && PyDict_Size(kwds) != 0) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"FrameLocalsProxy takes no keyword arguments");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyFrameLocalsProxyObject *self = (PyFrameLocalsProxyObject *)type->tp_alloc(type, 0);
|
||||
if (self == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyFrameObject *frame = (PyFrameObject*)PyTuple_GET_ITEM(args, 0);
|
||||
assert(PyFrame_Check(frame));
|
||||
|
||||
((PyFrameLocalsProxyObject*)self)->frame = (PyFrameObject*)Py_NewRef(frame);
|
||||
|
||||
return (PyObject *)self;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue