Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
5db5426e
Commit
5db5426e
authored
Feb 15, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the real safe_exec; make the seed available in the context.
parent
19e3a0ce
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
5 deletions
+13
-5
common/lib/capa/capa/capa_problem.py
+1
-0
common/lib/capa/capa/responsetypes.py
+1
-2
common/lib/codejail/codejail/safe_exec.py
+11
-3
No files found.
common/lib/capa/capa/capa_problem.py
View file @
5db5426e
...
...
@@ -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
)
...
...
common/lib/capa/capa/responsetypes.py
View file @
5db5426e
...
...
@@ -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
)
...
...
common/lib/codejail/codejail/safe_exec.py
View file @
5db5426e
...
...
@@ -52,9 +52,12 @@ if lazymod_py_file.endswith("c"):
lazymod_py
=
open
(
lazymod_py_file
)
.
read
()
def
xxx
safe_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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment