From 61798bdb357490f3fa61ab14efc24f7472e4a6d0 Mon Sep 17 00:00:00 2001 From: Arvid Lunnemark Date: Fri, 20 Aug 2021 02:57:22 +0200 Subject: [PATCH] disallow objects --- engine/malthusia/engine/container/runner.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/engine/malthusia/engine/container/runner.py b/engine/malthusia/engine/container/runner.py index 46a12fa..9986a7c 100644 --- a/engine/malthusia/engine/container/runner.py +++ b/engine/malthusia/engine/container/runner.py @@ -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 @@ -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