]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
authorSteve Dower <steve.dower@microsoft.com>
Sat, 4 Feb 2017 22:54:56 +0000 (14:54 -0800)
committerSteve Dower <steve.dower@microsoft.com>
Sat, 4 Feb 2017 22:54:56 +0000 (14:54 -0800)
Lib/pathlib.py
Lib/test/test_pathlib.py
Misc/NEWS

index 1480e2fc71aaac4b9c54b862c6cfb945f249ea08..c0d858ef56120aa471e8cbaf5a71dc5a30495ec6 100644 (file)
@@ -1222,7 +1222,7 @@ class Path(PurePath):
                 if not exist_ok or not self.is_dir():
                     raise
             except OSError as e:
-                if e.errno != ENOENT:
+                if e.errno != ENOENT or self.parent == self:
                     raise
                 self.parent.mkdir(parents=True)
                 self._accessor.mkdir(self, mode)
index fa96d9f882c9e2baa61fb73dbc34acb584ad3ac7..28e3ea4da6e28c573ca4e52037563b727734073b 100644 (file)
@@ -1727,6 +1727,17 @@ class _BasePathTest(object):
         self.assertTrue(p.exists())
         self.assertEqual(p.stat().st_ctime, st_ctime_first)
 
+    @only_nt    # XXX: not sure how to test this on POSIX
+    def test_mkdir_with_unknown_drive(self):
+        for d in 'ZYXWVUTSRQPONMLKJIHGFEDCBA':
+            p = self.cls(d + ':\\')
+            if not p.is_dir():
+                break
+        else:
+            self.skipTest("cannot find a drive that doesn't exist")
+        with self.assertRaises(OSError):
+            (p / 'child' / 'path').mkdir(parents=True)
+
     def test_mkdir_with_child_file(self):
         p = self.cls(BASE, 'dirB', 'fileB')
         self.assertTrue(p.exists())
index 55303a51af18b60379267854adea9c0b9d53d94f..9dac6302ca2b6385fcd191242cdc2e0899e24e4a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,8 @@ Extension Modules
 Library
 -------
 
+- Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
+
 - Issue #29444: Fixed out-of-bounds buffer access in the group() method of
   the match object.  Based on patch by WGH.