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
182a1a18
Commit
182a1a18
authored
Mar 28, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanups
parent
0021b0ac
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
7 deletions
+18
-7
common/lib/codejail/codejail/django_integration.py
+1
-0
common/lib/codejail/codejail/jailpy.py
+8
-3
common/lib/codejail/codejail/safe_exec.py
+3
-3
common/lib/codejail/codejail/tests/test_jailpy.py
+2
-0
common/lib/codejail/codejail/tests/test_safe_exec.py
+2
-0
common/lib/codejail/codejail/util.py
+2
-1
No files found.
common/lib/codejail/codejail/django_integration.py
View file @
182a1a18
...
...
@@ -5,6 +5,7 @@ from django.conf import settings
import
codejail.jailpy
class
ConfigureCodeJailMiddleware
(
object
):
"""Middleware to configure codejail on startup."""
...
...
common/lib/codejail/codejail/jailpy.py
View file @
182a1a18
...
...
@@ -4,7 +4,8 @@
# - AppArmor.md from xserver
import
logging
import
os
,
os
.
path
import
os
import
os.path
import
resource
import
shutil
import
subprocess
...
...
@@ -22,6 +23,7 @@ log = logging.getLogger(__name__)
PYTHON_CMD
=
None
def
configure
(
python_bin
,
user
=
None
):
"""Configure the jailpy module."""
global
PYTHON_CMD
...
...
@@ -30,6 +32,7 @@ def configure(python_bin, user=None):
PYTHON_CMD
.
extend
([
'sudo'
,
'-u'
,
'sandbox'
])
PYTHON_CMD
.
extend
([
python_bin
,
'-E'
])
def
is_configured
():
return
bool
(
PYTHON_CMD
)
...
...
@@ -42,7 +45,9 @@ if hasattr(sys, 'real_prefix'):
class
JailResult
(
object
):
"""A passive object for us to return from jailpy."""
pass
def
__init__
(
self
):
self
.
stdout
=
self
.
stderr
=
self
.
status
=
None
def
jailpy
(
code
,
files
=
None
,
argv
=
None
,
stdin
=
None
):
"""
...
...
@@ -104,7 +109,7 @@ def set_process_limits():
resource
.
setrlimit
(
resource
.
RLIMIT_NPROC
,
(
0
,
0
))
# no subprocesses
resource
.
setrlimit
(
resource
.
RLIMIT_FSIZE
,
(
0
,
0
))
# no files
mem
=
32
*
2
**
20
# 32 MB should be enough for anyone, right? :)
mem
=
32
*
(
2
**
20
)
# 32 MB should be enough for anyone, right? :)
resource
.
setrlimit
(
resource
.
RLIMIT_STACK
,
(
mem
,
mem
))
resource
.
setrlimit
(
resource
.
RLIMIT_RSS
,
(
mem
,
mem
))
resource
.
setrlimit
(
resource
.
RLIMIT_DATA
,
(
mem
,
mem
))
...
...
common/lib/codejail/codejail/safe_exec.py
View file @
182a1a18
...
...
@@ -6,9 +6,9 @@ import shutil
import
sys
import
textwrap
import
jailpy
from
codejail
import
jailpy
from
codejail.util
import
temp_directory
,
change_directory
from
util
import
temp_directory
,
change_directory
def
safe_exec
(
code
,
globals_dict
,
files
=
None
,
python_path
=
None
):
"""Execute code as "exec" does, but safely.
...
...
@@ -98,7 +98,7 @@ def json_safe(d):
ok_types
=
(
type
(
None
),
int
,
long
,
float
,
str
,
unicode
,
list
,
tuple
,
dict
)
bad_keys
=
(
"__builtins__"
,)
jd
=
{}
for
k
,
v
in
d
.
iteritems
():
for
k
,
v
in
d
.
iteritems
():
if
not
isinstance
(
v
,
ok_types
):
continue
if
k
in
bad_keys
:
...
...
common/lib/codejail/codejail/tests/test_jailpy.py
View file @
182a1a18
...
...
@@ -9,6 +9,7 @@ from codejail.jailpy import jailpy, is_configured
dedent
=
textwrap
.
dedent
class
JailPyHelpers
(
object
):
"""Assert helpers for jailpy tests."""
def
setUp
(
self
):
...
...
@@ -112,6 +113,7 @@ class TestLimits(JailPyHelpers, unittest.TestCase):
# TODO: read network
# TODO: fork
class
TestMalware
(
JailPyHelpers
,
unittest
.
TestCase
):
def
test_crash_cpython
(
self
):
# http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
...
...
common/lib/codejail/codejail/tests/test_safe_exec.py
View file @
182a1a18
...
...
@@ -7,6 +7,7 @@ from nose.plugins.skip import SkipTest
from
codejail.safe_exec
import
safe_exec
,
not_safe_exec
class
SafeExecTests
(
object
):
"""The tests for `safe_exec`, will be mixed into specific test classes below."""
def
test_set_values
(
self
):
...
...
@@ -60,6 +61,7 @@ class TestSafeExec(SafeExecTests, unittest.TestCase):
def
safe_exec
(
self
,
*
args
,
**
kwargs
):
safe_exec
(
*
args
,
**
kwargs
)
class
TestNotSafeExec
(
SafeExecTests
,
unittest
.
TestCase
):
"""Run SafeExecTests, with not_safe_exec."""
def
setUp
(
self
):
...
...
common/lib/codejail/codejail/util.py
View file @
182a1a18
...
...
@@ -3,7 +3,6 @@
import
contextlib
import
os
import
shutil
import
sys
import
tempfile
...
...
@@ -19,6 +18,7 @@ class TempDirectory(object):
# if this errors, something is genuinely wrong, so don't ignore errors.
shutil
.
rmtree
(
self
.
temp_dir
)
@contextlib.contextmanager
def
temp_directory
(
delete_when_done
=
True
):
"""
...
...
@@ -40,6 +40,7 @@ class ChangeDirectory(object):
def
clean_up
(
self
):
os
.
chdir
(
self
.
old_dir
)
@contextlib.contextmanager
def
change_directory
(
new_dir
):
"""
...
...
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