[pypy-commit] pypy default: fix sandbox in the case where an os function is called directly via rposix, as

cfbolz pypy.commits at gmail.com
Wed Nov 23 05:57:13 EST 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r88576:f8b82bd65934
Date: 2016-11-23 11:55 +0100
http://bitbucket.org/pypy/pypy/changeset/f8b82bd65934/

Log:	fix sandbox in the case where an os function is called directly via
	rposix, as opposed to via os.

diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -323,6 +323,8 @@
 def register_replacement_for(replaced_function, sandboxed_name=None):
     def wrap(func):
         from rpython.rtyper.extregistry import ExtRegistryEntry
+        # to support calling func directly
+        func._sandbox_external_name = sandboxed_name
         class ExtRegistry(ExtRegistryEntry):
             _about_ = replaced_function
             def compute_annotation(self):
diff --git a/rpython/translator/sandbox/test/test_sandbox.py b/rpython/translator/sandbox/test/test_sandbox.py
--- a/rpython/translator/sandbox/test/test_sandbox.py
+++ b/rpython/translator/sandbox/test/test_sandbox.py
@@ -65,6 +65,24 @@
     f.close()
     assert tail == ""
 
+def test_open_dup_rposix():
+    from rpython.rlib import rposix
+    def entry_point(argv):
+        fd = rposix.open("/tmp/foobar", os.O_RDONLY, 0777)
+        assert fd == 77
+        fd2 = rposix.dup(fd)
+        assert fd2 == 78
+        return 0
+
+    exe = compile(entry_point)
+    g, f = run_in_subprocess(exe)
+    expect(f, g, "ll_os.ll_os_open", ("/tmp/foobar", os.O_RDONLY, 0777), 77)
+    expect(f, g, "ll_os.ll_os_dup",  (77, True), 78)
+    g.close()
+    tail = f.read()
+    f.close()
+    assert tail == ""
+
 def test_read_write():
     def entry_point(argv):
         fd = os.open("/tmp/foobar", os.O_RDONLY, 0777)


More information about the pypy-commit mailing list