Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
codejail
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
codejail
Commits
906898b1
Commit
906898b1
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
37016b0e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
codejail/safe_exec.py
+11
-3
No files found.
codejail/safe_exec.py
View file @
906898b1
...
@@ -52,9 +52,12 @@ if lazymod_py_file.endswith("c"):
...
@@ -52,9 +52,12 @@ if lazymod_py_file.endswith("c"):
lazymod_py
=
open
(
lazymod_py_file
)
.
read
()
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
=
[]
the_code
=
[]
if
future_division
:
the_code
.
append
(
"from __future__ import division
\n
"
)
the_code
.
append
(
textwrap
.
dedent
(
"""
\
the_code
.
append
(
textwrap
.
dedent
(
"""
\
import json
import json
import sys
import sys
...
@@ -73,12 +76,17 @@ def xxxsafe_exec(code, globals_dict, locals_dict, future_division=False, assumed
...
@@ -73,12 +76,17 @@ def xxxsafe_exec(code, globals_dict, locals_dict, future_division=False, assumed
the_code
.
append
(
textwrap
.
dedent
(
"""
\
the_code
.
append
(
textwrap
.
dedent
(
"""
\
exec code in g_dict, l_dict
exec code in g_dict, l_dict
print >>sys.stderr, l_dict.keys()
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)}
l_dict = {k:v for k,v in l_dict.iteritems() if isinstance(v, ok_types)}
json.dump(l_dict, sys.stdout)
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
])
stdin
=
json
.
dumps
([
code
,
globals_dict
,
locals_dict
])
res
=
jailpy
.
jailpy
(
""
.
join
(
the_code
),
stdin
=
stdin
)
res
=
jailpy
.
jailpy
(
""
.
join
(
the_code
),
stdin
=
stdin
)
if
res
.
status
!=
0
:
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