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
ac4c37d4
Commit
ac4c37d4
authored
May 13, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent the environment from leaking into the sandbox.
parent
e4151f31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
1 deletions
+16
-1
codejail/jail_code.py
+5
-1
codejail/tests/test_jailpy.py
+11
-0
No files found.
codejail/jail_code.py
View file @
ac4c37d4
...
...
@@ -33,8 +33,12 @@ def configure(command, bin_path, user=None):
"""
cmd_argv
=
[]
if
user
:
# Run as the specified user
cmd_argv
.
extend
([
'sudo'
,
'-u'
,
user
])
# Run the command!
cmd_argv
.
append
(
bin_path
)
# Command-specific arguments
...
...
@@ -154,7 +158,7 @@ def jail_code(command, code=None, files=None, argv=None, stdin=None):
cmd
=
COMMANDS
[
command
]
+
argv
subproc
=
subprocess
.
Popen
(
cmd
,
preexec_fn
=
set_process_limits
,
cwd
=
tmpdir
,
cmd
,
preexec_fn
=
set_process_limits
,
cwd
=
tmpdir
,
env
=
{},
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
)
...
...
codejail/tests/test_jailpy.py
View file @
ac4c37d4
"""Test jail_code.py"""
import
os
import
os.path
import
textwrap
import
unittest
...
...
@@ -138,6 +139,16 @@ class TestLimits(JailCodeHelpers, unittest.TestCase):
self
.
assertEqual
(
res
.
stdout
,
"Forking
\n
"
)
self
.
assertIn
(
"OSError"
,
res
.
stderr
)
def
test_cant_see_environment_variables
(
self
):
os
.
environ
[
'HONEY_BOO_BOO'
]
=
'Look!'
res
=
jailpy
(
code
=
dedent
(
"""
\
import os
for name, value in os.environ.items():
print "
%
s:
%
r"
%
(name, value)
"""
))
self
.
assertResultOk
(
res
)
self
.
assertNotIn
(
"HONEY"
,
res
.
stdout
)
class
TestChangingLimits
(
JailCodeHelpers
,
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
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