]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Deny eval() direct access to builtins (GH-20713)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Mon, 8 Jun 2020 06:51:40 +0000 (23:51 -0700)
committerGitHub <noreply@github.com>
Mon, 8 Jun 2020 06:51:40 +0000 (23:51 -0700)
Lib/collections/__init__.py

index 03393f35b11c507967293f49d1ba83694e8575b5..1e3b54ccf9cc96f068bd3613f100e5561338380d 100644 (file)
@@ -407,7 +407,8 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
     # Create all the named tuple methods to be added to the class namespace
 
     s = f'lambda _cls, {arg_list}: _tuple_new(_cls, ({arg_list}))'
-    namespace = {'_tuple_new': tuple_new, '__name__': f'namedtuple_{typename}'}
+    namespace = {'_tuple_new': tuple_new,  '__builtins__': None,
+                 '__name__': f'namedtuple_{typename}'}
     __new__ = eval(s, namespace)
     __new__.__doc__ = f'Create new instance of {typename}({arg_list})'
     if defaults is not None: