mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-132386: Fix a crash when passing a dict subclass to exec
(GH-132412)
* Fix crash when passing a dict subclass to exec * Add news entry
This commit is contained in:
parent
deda47d6e1
commit
e6ef47ac22
3 changed files with 14 additions and 0 deletions
|
@ -1636,6 +1636,16 @@ class TestSpecifics(unittest.TestCase):
|
|||
pass
|
||||
[[]]
|
||||
|
||||
def test_globals_dict_subclass(self):
|
||||
# gh-132386
|
||||
class WeirdDict(dict):
|
||||
pass
|
||||
|
||||
ns = {}
|
||||
exec('def foo(): return a', WeirdDict(), ns)
|
||||
|
||||
self.assertRaises(NameError, ns['foo'])
|
||||
|
||||
class TestBooleanExpression(unittest.TestCase):
|
||||
class Value:
|
||||
def __init__(self):
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix crash when passing a dict subclass as the ``globals`` parameter to
|
||||
:func:`exec`.
|
|
@ -3312,6 +3312,8 @@ _PyEval_LoadGlobalStackRef(PyObject *globals, PyObject *builtins, PyObject *name
|
|||
_PyEval_FormatExcCheckArg(
|
||||
PyThreadState_GET(), PyExc_NameError,
|
||||
NAME_ERROR_MSG, name);
|
||||
*writeto = PyStackRef_NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
*writeto = PyStackRef_FromPyObjectSteal(res);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue