Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disallow objects #3

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions engine/malthusia/engine/container/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, code, game_methods, log_method, error_method, debug=False):
self.globals['__builtins__']['__multinstrument__'] = self.multinstrument_call
self.globals['__builtins__']['__import__'] = self.import_call
self.globals['__builtins__']['_getitem_'] = self.getitem_call
self.globals['__builtins__']['_write_'] = self.write_call
self.globals['__builtins__']['_write_'] = lambda obj: self.write_call(obj, game_methods.values())
self.globals['__builtins__']['_getiter_'] = lambda i: i
self.globals['__builtins__']['_inplacevar_'] = self.inplacevar_call
self.globals['__builtins__']['_unpack_sequence_'] = Guards.guarded_unpack_sequence
Expand Down Expand Up @@ -122,13 +122,16 @@ def inplacevar_call(op, x, y):
raise SyntaxError('Unsupported in place op "' + op + '".')

@staticmethod
def write_call(obj):
def write_call(obj, disallowed_objs):
if isinstance(obj, type(sys)):
raise RuntimeError('Can\'t write to modules.')

elif isinstance(obj, type(lambda: 1)):
raise RuntimeError('Can\'t write to functions.')

elif obj in disallowed_objs:
raise RuntimeError(f'Can\'t write to {obj}')

return obj

@staticmethod
Expand Down