summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-02-04 14:56:57 -0800
committerSteve Dower <steve.dower@microsoft.com>2017-02-04 14:56:57 -0800
commitf687fbcd73c14dfcbe086eb5cd94b298f1e81e72 (patch)
tree49023a177430af6291f33d14c2540ff7d46b10ca
parent44a28ecbe2c09fe5ec4959c254fdfe5b6a9fe322 (diff)
parentb53654b6dbfce8318a7d4d1cdaddca7a7fec194b (diff)
downloadcpython-f687fbcd73c14dfcbe086eb5cd94b298f1e81e72.tar.gz
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 0484dacd79..9f347216b1 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 ce1ca153ed..88a93e5802 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 0d77f02178..494f314879 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -223,6 +223,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.