summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-02-04 22:55:16 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2017-02-04 22:55:16 (GMT)
commit1add96f1b669436ca96dc8adf24276adea6aea4c (patch)
treefbe866bb72d207ba611f8f72b12e7d08d121a0c2
parent86e42376c2f41e6601b1844fb127f2f2e7b5349a (diff)
parentd3c4853b7869b347462343fd9df99f998e0eb018 (diff)
downloadcpython-1add96f1b669436ca96dc8adf24276adea6aea4c.zip
cpython-1add96f1b669436ca96dc8adf24276adea6aea4c.tar.gz
cpython-1add96f1b669436ca96dc8adf24276adea6aea4c.tar.bz2
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
-rw-r--r--Lib/pathlib.py2
-rw-r--r--Lib/test/test_pathlib.py11
-rw-r--r--Misc/NEWS2
3 files changed, 14 insertions, 1 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 0484dac..9f34721 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -1235,7 +1235,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)
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index ce1ca15..88a93e5 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1776,6 +1776,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())
diff --git a/Misc/NEWS b/Misc/NEWS
index 097bd26..34083c8 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -55,6 +55,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.