Author: Armin Rigo <ar...@tunes.org>
Branch: py3.5
Changeset: r89471:f9c35809153c
Date: 2017-01-10 12:20 +0100
http://bitbucket.org/pypy/pypy/changeset/f9c35809153c/

Log:    Check that the 'opener' of the file constructors don't return a
        negative fd

diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -194,6 +194,11 @@
                 w_fd = space.call_function(w_opener, w_name, space.wrap(flags))
                 try:
                     self.fd = space.int_w(w_fd)
+                    if self.fd < 0:
+                        # The opener returned a negative result instead
+                        # of raising an exception
+                        raise oefmt(space.w_ValueError,
+                                    "opener returned %d", self.fd)
                     fd_is_own = True
                 except OperationError as e:
                     if not e.match(space, space.w_TypeError):
diff --git a/pypy/module/_io/test/test_fileio.py 
b/pypy/module/_io/test/test_fileio.py
--- a/pypy/module/_io/test/test_fileio.py
+++ b/pypy/module/_io/test/test_fileio.py
@@ -282,6 +282,12 @@
         if fd1 != fd2:
             raises(OSError, posix.close, fd1)
 
+    def test_opener_negative(self):
+        import _io
+        def opener(*args):
+            return -1
+        raises(ValueError, _io.FileIO, "foo", 'r', opener=opener)
+
 
 def test_flush_at_exit():
     from pypy import conftest
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to