[pypy-svn] r45822 - pypy/branch/pypy-more-rtti-inprogress/translator/sandbox
arigo at codespeak.net
arigo at codespeak.net
Fri Aug 17 18:01:15 CEST 2007
Author: arigo
Date: Fri Aug 17 18:01:14 2007
New Revision: 45822
Added:
pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/autopath.py
- copied unchanged from r45812, pypy/branch/pypy-more-rtti-inprogress/translator/autopath.py
Modified:
pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/pypy_interact.py
pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/sandlib.py
Log:
Some progress. Now we need a way to report OSErrors back inside.
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/pypy_interact.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/pypy_interact.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/pypy_interact.py Fri Aug 17 18:01:14 2007
@@ -6,20 +6,29 @@
pypy_interact.py <executable> <args...>
"""
-import sys
+import sys, os
+import autopath
+from pypy.tool.udir import udir
from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc
from pypy.translator.sandbox.sandlib import VirtualizedSandboxedProc
class PyPySandboxedProc(VirtualizedSandboxedProc, SimpleIOSandboxedProc):
- argv0 = '/usr/bin/pypy-c'
+ argv0 = '/opt/pypy-c'
virtual_cwd = '/tmp'
virtual_env = {}
def __init__(self, executable, arguments):
super(PyPySandboxedProc, self).__init__([self.argv0] + arguments,
executable=executable)
+ pypydist = os.path.dirname(os.path.abspath(autopath.pypydir))
self.path_mapping = {
- self.argv0: executable, # can access its own executable
+ # can access its own executable
+ self.argv0: executable,
+ # can access the pure Python libraries
+ '/opt/lib-python': os.path.join(pypydist, 'lib-python'),
+ '/opt/pypy/lib': os.path.join(pypydist, 'pypy', 'lib'),
+ # can access the temporary usession directory as /tmp
+ self.virtual_cwd: str(udir),
}
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/sandlib.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/sandlib.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/sandbox/sandlib.py Fri Aug 17 18:01:14 2007
@@ -147,14 +147,17 @@
"""
virtual_env = {}
virtual_cwd = '/tmp'
- path_mapping = {} # maps virtual paths to real paths or None
+ path_mapping = {} # maps virtual paths to real paths
def do_ll_os__ll_os_envitems(self):
return self.virtual_env.items()
+ def do_ll_os__ll_os_getenv(self, name):
+ return self.virtual_env.get(name)
+
def translate_path(self, vpath):
# XXX this assumes posix vpaths for now, but os-specific real paths
- vpath = posixpath.join(self.virtual_cwd, vpath)
+ vpath = posixpath.normpath(posixpath.join(self.virtual_cwd, vpath))
components = [component for component in vpath.split('/') if component]
# find the longest match in self.path_mapping
for i in range(len(components), -1, -1):
@@ -165,7 +168,11 @@
raise VirtualOSError("no access to vpath %r" % (vpath,))
result = self.path_mapping[test]
if i < len(components):
- result = os.path.join(result, *components[i:])
+ # forbid escapes via '..'
+ remaining_components = components[i:]
+ if os.pardir in remaining_components:
+ raise VirtualOSError("dangerous '..' in %r" % (vpath,))
+ result = os.path.join(result, *remaining_components)
if vpath.endswith(os.sep):
result += os.sep # re-add a trailing '/' if one was specified
print 'VPATH:', vpath, '=>', result
@@ -176,6 +183,12 @@
result += (0,) * (len(STAT_FIELDS) - len(result))
return result
+ def do_ll_os__ll_os_stat(self, vpathname):
+ pathname = self.translate_path(vpathname)
+ st = os.stat(pathname)
+ return self.build_stat_result(st)
+ do_ll_os__ll_os_stat.resulttype = s_tuple_StatResult
+
def do_ll_os__ll_os_lstat(self, vpathname):
pathname = self.translate_path(vpathname)
st = os.lstat(pathname)
More information about the Pypy-commit
mailing list