Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add the possibility of showing the stacktrace when an exeption in raise in the sandboxed code #14

Closed
wants to merge 1 commit into from

2 participants

@xcombelle

the use is as follow

def f():
    x
from sandbox import Sandbox, SandboxConfig,SandboxError
sandbox = Sandbox(SandboxConfig('stderr',use_subprocess=True))
try:
    result = sandbox.call(f)
except SandboxError as e:
    if hasattr(e,'stacktrace'):
        print (e.stacktrace)
    else:
        raise

moreover the modifications remove a security issue as the Exception was previously pickled and could be execute untrested code when unpickled

Xavier Combelle show stacktrace 1bbc63e
@haypo
Owner

I now consider the pysandbox project is broken by design, so I'm not going to modify it anymore, sorry.

@haypo haypo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 13, 2012
  1. show stacktrace

    Xavier Combelle authored
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 7 deletions.
  1. +3 −3 sandbox/subprocess_child.py
  2. +9 −4 sandbox/subprocess_parent.py
View
6 sandbox/subprocess_child.py
@@ -3,7 +3,7 @@
import os
import pickle
from sandbox import Sandbox
-
+import traceback
try:
import resource
except ImportError:
@@ -66,7 +66,7 @@ def execute_child():
if 'locals' in input_data:
output_data['locals'] = locals
except base_exception, err:
- output_data = {'error': err}
+ output_data = {'stacktrace': traceback.format_exc()}
pickle.dump(output_data, output, PICKLE_PROTOCOL)
output.flush()
output.close()
@@ -78,7 +78,7 @@ def call_child(wpipe, sandbox, func, args, kw):
result = sandbox._call(func, args, kw)
data = {'result': result}
except BaseException, err:
- data = {'error': err}
+ data = {'stacktrace': traceback.format_exc()}
output = os.fdopen(wpipe, 'wb')
pickle.dump(data, output, PICKLE_PROTOCOL)
output.flush()
View
13 sandbox/subprocess_parent.py
@@ -40,8 +40,11 @@ def call_parent(pid, rpipe):
data = pickle.load(rpipe_file)
finally:
rpipe_file.close()
- if 'error' in data:
- raise data['error']
+ if 'stacktrace' in data:
+ error = SandboxError('Exception raised')
+ error.stacktrace = data['stacktrace']
+ raise error
+
return data['result']
def call_fork(sandbox, func, args, kw):
@@ -115,8 +118,10 @@ def execute_subprocess(sandbox, code, globals, locals):
input_file.close()
output_file.close()
- if 'error' in output_data:
- raise output_data['error']
+ if 'stacktrace' in output_data:
+ error = SandboxError('Exception raised')
+ error.stacktrace = output_data['stacktrace']
+ raise error
if locals is not None:
locals.clear()
locals.update(output_data['locals'])
Something went wrong with that request. Please try again.