Will nested scoping break restricted execution ??
Tim Peters
tim.one at home.com
Sat Feb 3 23:20:02 EST 2001
[Martin von Loewis]
> ...
> I believe there isn't a way to prevent restricted code from accessing
> a specific __builtin__, either - instead, you have to provide
> alternative or missing versions of the builtins in advance.
RExec.nok_builtin_names is a tuple of the builtin names to be rendered
invisible. A subclass can define its own tuple of forbidden builtins.
Attempts to reference one of these names in restricted code just raises a
NameError, because it's plain missing:
>>> from rexec import RExec
>>> class NoIntRExec(RExec):
... nok_builtin_names = RExec.nok_builtin_names + ("int",)
...
>>> def int_abuser():
... print int(44.4)
...
>>> RExec().r_exec(int_abuser.func_code) # fine by regular RExec
44
>>> NoIntRExec().r_exec(int_abuser.func_code) # but not mine
Traceback (most recent call last):
File "<stdin>", line 1, in ?
... [lotsa rexec stuff] ...
File "c:\code\python\dist\src\lib\ihooks.py", line 326, in load_module
exec code in m.__dict__
File "c:\code\python\dist\src\lib\string.py", line 189, in ?
_int = int
NameError: name 'int' is not defined
>>>
simple-and-effective-is-a-delightful-combo-ly y'rs - tim
More information about the Python-list
mailing list