summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-08-24 15:37:12 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-08-24 15:37:12 (GMT)
commite37375405657413ef9b83b935bb4ed17cd745ce6 (patch)
tree0a01a598741e39eaa4876540e580f236b9731d6d /Lib
parentd3ea06537ca902ff1fb034f014232b5970fabda7 (diff)
downloadcpython-e37375405657413ef9b83b935bb4ed17cd745ce6.zip
cpython-e37375405657413ef9b83b935bb4ed17cd745ce6.tar.gz
cpython-e37375405657413ef9b83b935bb4ed17cd745ce6.tar.bz2
don't segfault when trying to fdopen() a fd for a dir (closes #22259)
Patch from Brian Kearns.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_posix.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index df122f7..3f44aa3 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -194,6 +194,18 @@ class PosixTester(unittest.TestCase):
self.fdopen_helper('r')
self.fdopen_helper('r', 100)
+ @unittest.skipUnless(hasattr(posix, 'fdopen'),
+ 'test needs posix.fdopen()')
+ def test_fdopen_directory(self):
+ try:
+ fd = os.open('.', os.O_RDONLY)
+ except OSError as e:
+ self.assertEqual(e.errno, errno.EACCES)
+ self.skipTest("system cannot open directories")
+ with self.assertRaises(IOError) as cm:
+ os.fdopen(fd, 'r')
+ self.assertEqual(cm.exception.errno, errno.EISDIR)
+
@unittest.skipUnless(hasattr(posix, 'fdopen') and
not sys.platform.startswith("sunos"),
'test needs posix.fdopen()')