cpython: 62b9bfbc3356 (original) (raw)
Mercurial > cpython
changeset 77951:62b9bfbc3356
Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open. [#15261]
Richard Oudkerk shibturn@gmail.com | |
---|---|
date | Fri, 06 Jul 2012 12:05:32 +0100 |
parents | 61e6ac40c816 |
children | b7cfdb48af62 |
files | Doc/library/os.path.rst Lib/test/test_genericpath.py Lib/test/test_os.py Misc/NEWS Modules/posixmodule.c |
diffstat | 5 files changed, 37 insertions(+), 6 deletions(-)[+] [-] Doc/library/os.path.rst 11 Lib/test/test_genericpath.py 10 Lib/test/test_os.py 13 Misc/NEWS 2 Modules/posixmodule.c 7 |
line wrap: on
line diff
--- a/Doc/library/os.path.rst +++ b/Doc/library/os.path.rst @@ -70,11 +70,16 @@ applications should use string objects t .. function:: exists(path)
- Return
True
if path refers to an existing path. ReturnsFalse
for - broken symbolic links. On some platforms, this function may return
False
if - permission is not granted to execute :func:
os.stat
on the requested file, even
- Return
True
if path refers to an existing path or an open - file descriptor. Returns
False
for broken symbolic links. On - some platforms, this function may return
False
if permission is - not granted to execute :func:
os.stat
on the requested file, even if the path physically exists. - .. versionchanged:: 3.3
*path* can now be an integer: ``True`` is returned if it is an[](#l1.17)
open file descriptor, ``False`` otherwise.[](#l1.18)
--- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@ -146,6 +146,16 @@ class GenericTest(unittest.TestCase): f.close() support.unlink(support.TESTFN)
- @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()")
- def test_exists_fd(self):
r, w = os.pipe()[](#l2.9)
try:[](#l2.10)
self.assertTrue(self.pathmodule.exists(r))[](#l2.11)
finally:[](#l2.12)
os.close(r)[](#l2.13)
os.close(w)[](#l2.14)
self.assertFalse(self.pathmodule.exists(r))[](#l2.15)
+ def test_isdir(self): self.assertIs(self.pathmodule.isdir(support.TESTFN), False) f = open(support.TESTFN, "wb")
--- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -473,6 +473,19 @@ class StatAttributeTests(unittest.TestCa return self.fail("Could not stat pagefile.sys")
@unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()")[](#l3.7)
def test_15261(self):[](#l3.8)
# Verify that stat'ing a closed fd does not cause crash[](#l3.9)
r, w = os.pipe()[](#l3.10)
try:[](#l3.11)
os.stat(r) # should not raise error[](#l3.12)
finally:[](#l3.13)
os.close(r)[](#l3.14)
os.close(w)[](#l3.15)
with self.assertRaises(OSError) as ctx:[](#l3.16)
os.stat(r)[](#l3.17)
self.assertEqual(ctx.exception.errno, errno.EBADF)[](#l3.18)
+ from test import mapping_tests class EnvironTests(mapping_tests.BasicTestMappingProtocol):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -23,6 +23,8 @@ Core and Builtins Library ------- +- Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open. +
- Issue #15166: Implement imp.get_tag() using sys.implementation.cache_tag.
- Issue #15210: Catch KeyError when imprortlib.init can't find
--- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1829,7 +1829,10 @@ win32_fstat(int file_number, struct win3 HANDLE h; int type;
- if (!_PyVerify_fd(file_number))
h = INVALID_HANDLE_VALUE;[](#l5.9)
- else
h = (HANDLE)_get_osfhandle(file_number);[](#l5.11)
/* Protocol violation: we explicitly clear errno, instead of setting it to a POSIX error. Callers should use GetLastError. */ @@ -8244,8 +8247,6 @@ posix_fstat(PyObject *self, PyObject ar / on OpenVMS we must ensure that all bytes are written to the file */ fsync(fd); #endif