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
45a329ca
Commit
45a329ca
authored
May 16, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Line length and indentation fixes.
parent
54d3f77e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
16 deletions
+30
-16
codejail/safe_exec.py
+16
-5
codejail/tests/test_jailpy.py
+7
-4
codejail/tests/test_safe_exec.py
+1
-1
codejail/util.py
+2
-1
pylintrc
+4
-5
No files found.
codejail/safe_exec.py
View file @
45a329ca
...
...
@@ -98,7 +98,9 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
"""
# Clean the globals for sending back as JSON over stdout.
"""
ok_types = (type(None), int, long, float, str, unicode, list, tuple, dict)
ok_types = (
type(None), int, long, float, str, unicode, list, tuple, dict
)
bad_keys = ("__builtins__",)
def jsonable(v):
if not isinstance(v, ok_types):
...
...
@@ -108,7 +110,11 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
except Exception:
return False
return True
g_dict = {k:v for k,v in g_dict.iteritems() if jsonable(v) and k not in bad_keys}
g_dict = {
k:v
for k,v in g_dict.iteritems()
if jsonable(v) and k not in bad_keys
}
"""
# Write the globals back to the calling process.
"""
...
...
@@ -124,9 +130,13 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
log
.
debug
(
"Exec:
%
s"
,
code
)
log
.
debug
(
"Stdin:
%
s"
,
stdin
)
res
=
jail_code
.
jail_code
(
"python"
,
code
=
jailed_code
,
stdin
=
stdin
,
files
=
files
)
res
=
jail_code
.
jail_code
(
"python"
,
code
=
jailed_code
,
stdin
=
stdin
,
files
=
files
)
if
res
.
status
!=
0
:
raise
SafeExecException
(
"Couldn't execute jailed code:
%
s"
%
res
.
stderr
)
raise
SafeExecException
(
"Couldn't execute jailed code:
%
s"
%
res
.
stderr
)
globals_dict
.
update
(
json
.
loads
(
res
.
stdout
))
...
...
@@ -195,7 +205,8 @@ def not_safe_exec(code, globals_dict, files=None, python_path=None):
# Wrap the exception in a SafeExecException, but we don't
# try here to include the traceback, since this is just a
# substitute implementation.
raise
SafeExecException
(
"{0.__class__.__name__}: {0!s}"
.
format
(
e
))
msg
=
"{0.__class__.__name__}: {0!s}"
.
format
(
e
)
raise
SafeExecException
(
msg
)
finally
:
sys
.
path
=
original_path
...
...
codejail/tests/test_jailpy.py
View file @
45a329ca
...
...
@@ -99,7 +99,10 @@ class TestFeatures(JailCodeHelpers, unittest.TestCase):
argv
=
[
"doit.py"
,
"1"
,
"2"
,
"3"
]
)
self
.
assertResultOk
(
res
)
self
.
assertEqual
(
res
.
stdout
,
"This is doit.py!
\n
My args are ['doit.py', '1', '2', '3']
\n
"
)
self
.
assertEqual
(
res
.
stdout
,
"This is doit.py!
\n
My args are ['doit.py', '1', '2', '3']
\n
"
)
class
TestLimits
(
JailCodeHelpers
,
unittest
.
TestCase
):
...
...
@@ -262,7 +265,8 @@ class TestMalware(JailCodeHelpers, unittest.TestCase):
# http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
res
=
jailpy
(
code
=
dedent
(
"""
\
import new, sys
crash_me = new.function(new.code(0,0,0,0,"KABOOM",(),(),(),"","",0,""), {})
bad_code = new.code(0,0,0,0,"KABOOM",(),(),(),"","",0,"")
crash_me = new.function(bad_code, {})
print "Here we go..."
sys.stdout.flush()
crash_me()
...
...
@@ -285,8 +289,7 @@ class TestMalware(JailCodeHelpers, unittest.TestCase):
res
=
jailpy
(
code
=
dedent
(
"""
import os
places = [
"..", "/tmp", "/", "/home", "/etc",
"/var"
"..", "/tmp", "/", "/home", "/etc", "/var"
]
for place in places:
try:
...
...
codejail/tests/test_safe_exec.py
View file @
45a329ca
...
...
@@ -9,7 +9,7 @@ from codejail.safe_exec import safe_exec, not_safe_exec, SafeExecException
class
SafeExecTests
(
unittest
.
TestCase
):
"""The tests for `safe_exec`,
will be mixed into specific test classes below
."""
"""The tests for `safe_exec`,
to be mixed into specific test classes
."""
# SafeExecTests is a TestCase so pylint understands the methods it can
# call, but it's abstract, so stop nose from running the tests.
...
...
codejail/util.py
View file @
45a329ca
...
...
@@ -9,7 +9,8 @@ import tempfile
class
TempDirectory
(
object
):
def
__init__
(
self
):
self
.
temp_dir
=
tempfile
.
mkdtemp
(
prefix
=
"codejail-"
)
# Make directory readable by other users ('sandbox' user needs to be able to read it)
# Make directory readable by other users ('sandbox' user needs to be
# able to read it).
os
.
chmod
(
self
.
temp_dir
,
0775
)
def
clean_up
(
self
):
...
...
pylintrc
View file @
45a329ca
...
...
@@ -35,7 +35,6 @@ load-plugins=
# it should appear only once).
disable=
# Never going to use these
# C0301: Line too long
# W0142: Used * or ** magic
# W0141: Used builtin function 'map'
...
...
@@ -50,7 +49,7 @@ disable=
# R0912: Too many branches
# R0913: Too many arguments
# R0914: Too many local variables
C030
1,C030
2,W0141,W0142,R0201,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914
C0302,W0141,W0142,R0201,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914
[REPORTS]
...
...
@@ -68,7 +67,7 @@ include-ids=yes
files-output=no
# Tells whether to display a full report or only the messages
reports=
yes
reports=
no
# Python expression which should return a note less than 10 (10 is the highest
# note). You have access to the variables errors warning, statement which
...
...
@@ -157,7 +156,7 @@ bad-names=foo,bar,baz,toto,tutu,tata
# Regular expression which should only match functions or classes name which do
# not require a docstring
no-docstring-rgx=(__.*__|test_.*)
no-docstring-rgx=(__.*__|test_.*
|setUp|tearDown
)
[MISCELLANEOUS]
...
...
@@ -169,7 +168,7 @@ notes=FIXME,XXX,TODO
[FORMAT]
# Maximum number of characters on a single line.
max-line-length=
120
max-line-length=
79
# Maximum number of lines in a module
max-module-lines=1000
...
...
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