[pypy-svn] r75695 - in pypy/branch/fast-forward/pypy/module/posix: . test

benjamin at codespeak.net benjamin at codespeak.net
Wed Jun 30 20:36:09 CEST 2010


Author: benjamin
Date: Wed Jun 30 20:36:07 2010
New Revision: 75695

Modified:
   pypy/branch/fast-forward/pypy/module/posix/app_posix.py
   pypy/branch/fast-forward/pypy/module/posix/test/test_posix2.py
Log:
validate file descriptors to fdopen

Modified: pypy/branch/fast-forward/pypy/module/posix/app_posix.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/posix/app_posix.py	(original)
+++ pypy/branch/fast-forward/pypy/module/posix/app_posix.py	Wed Jun 30 20:36:07 2010
@@ -72,7 +72,12 @@
     """fdopen(fd [, mode='r' [, buffering]]) -> file_object
 
     Return an open file object connected to a file descriptor."""
-
+    # Validate fd
+    import fcntl
+    try:
+        fcntl.fcntl(fd, fcntl.F_GETFD)
+    except IOError, e:
+        raise OSError(e.errno, e.strerror, e.filename)
     return _fdopen(fd, mode, buffering)
 
 

Modified: pypy/branch/fast-forward/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/posix/test/test_posix2.py	(original)
+++ pypy/branch/fast-forward/pypy/module/posix/test/test_posix2.py	Wed Jun 30 20:36:07 2010
@@ -248,6 +248,7 @@
         fd = posix.open(path, posix.O_RDONLY, 0777)
         f = posix.fdopen(fd, "r")
         f.close()
+        raises(OSError, posix.fdopen, fd)
 
     def test_fdopen_hackedbuiltins(self):
         "Same test, with __builtins__.file removed"



More information about the Pypy-commit mailing list