Use the real safe_exec; make the seed available in the context.
This commit is contained in:
@@ -440,6 +440,7 @@ class LoncapaProblem(object):
|
||||
random.seed(self.seed)
|
||||
|
||||
context = {}
|
||||
context['seed'] = self.seed
|
||||
context['script_code'] = ''
|
||||
|
||||
self._execute_scripts(tree.findall('.//script'), context)
|
||||
|
||||
@@ -489,7 +489,7 @@ class JavascriptResponse(LoncapaResponse):
|
||||
output = self.call_node([generator_file,
|
||||
self.generator,
|
||||
json.dumps(self.generator_dependencies),
|
||||
json.dumps(str(self.context['the_lcp'].seed)),
|
||||
json.dumps(str(self.context['seed'])),
|
||||
json.dumps(self.params)]).strip()
|
||||
|
||||
return json.loads(output)
|
||||
@@ -1201,7 +1201,6 @@ class SymbolicResponse(CustomResponse):
|
||||
def setup_response(self):
|
||||
self.xml.set('cfn', 'symmath_check')
|
||||
code = "from symmath import *"
|
||||
raise Exception("exec 2")
|
||||
exec code in self.context, self.context
|
||||
CustomResponse.setup_response(self)
|
||||
|
||||
|
||||
@@ -52,9 +52,12 @@ if lazymod_py_file.endswith("c"):
|
||||
lazymod_py = open(lazymod_py_file).read()
|
||||
|
||||
|
||||
def xxxsafe_exec(code, globals_dict, locals_dict, future_division=False, assumed_imports=None):
|
||||
def safe_exec(code, globals_dict, locals_dict, future_division=False, assumed_imports=None):
|
||||
the_code = []
|
||||
|
||||
if future_division:
|
||||
the_code.append("from __future__ import division\n")
|
||||
|
||||
the_code.append(textwrap.dedent("""\
|
||||
import json
|
||||
import sys
|
||||
@@ -73,12 +76,17 @@ def xxxsafe_exec(code, globals_dict, locals_dict, future_division=False, assumed
|
||||
the_code.append(textwrap.dedent("""\
|
||||
exec code in g_dict, l_dict
|
||||
print >>sys.stderr, l_dict.keys()
|
||||
ok_types = (int, long, float, str, unicode, list, tuple, dict)
|
||||
ok_types = (type(None), int, long, float, str, unicode, list, tuple, dict)
|
||||
l_dict = {k:v for k,v in l_dict.iteritems() if isinstance(v, ok_types)}
|
||||
json.dump(l_dict, sys.stdout)
|
||||
"""))
|
||||
|
||||
print "".join(the_code)
|
||||
if 0:
|
||||
print "-- {:-<40}".format("jailed ")
|
||||
print "".join(the_code)
|
||||
print "-- {:-<40}".format("exec ")
|
||||
print code
|
||||
|
||||
stdin = json.dumps([code, globals_dict, locals_dict])
|
||||
res = jailpy.jailpy("".join(the_code), stdin=stdin)
|
||||
if res.status != 0:
|
||||
|
||||
Reference in New Issue
Block a user