Skip to content

Commit

Permalink
Merge pull request #3 from arvid220u/disallowclasswrites
Browse files Browse the repository at this point in the history
disallow objects
  • Loading branch information
arvid220u authored Aug 20, 2021
2 parents aa9479b + 61798bd commit a64deb3
Showing 1 changed file with 5 additions and 2 deletions.
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

0 comments on commit a64deb3

Please sign in to comment.