summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-09-25 19:41:09 (GMT)
committerGitHub <noreply@github.com>2024-09-25 19:41:09 (GMT)
commitd6954b6421aa34afd280df9c44ded21a2348a6ea (patch)
treea8bef4710328a6373712d618274459ab73153b6a /Objects
parent0d9d56c4e4246495f506f7fb319548fb105b535b (diff)
downloadcpython-d6954b6421aa34afd280df9c44ded21a2348a6ea.zip
cpython-d6954b6421aa34afd280df9c44ded21a2348a6ea.tar.gz
cpython-d6954b6421aa34afd280df9c44ded21a2348a6ea.tar.bz2
gh-124513: Check args in framelocalsproxy_new() (#124515)
Fix a crash in FrameLocalsProxy constructor: check the number of arguments.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/frameobject.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 9f1c031..f3a66ff 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -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;