From d3c4853b7869b347462343fd9df99f998e0eb018 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Sat, 4 Feb 2017 14:54:56 -0800 Subject: [PATCH] Issue #29416: Prevent infinite loop in pathlib.Path.mkdir --- Lib/pathlib.py | 2 +- Lib/test/test_pathlib.py | 11 +++++++++++ Misc/NEWS | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 1480e2fc71a..c0d858ef561 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -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) diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index fa96d9f882c..28e3ea4da6e 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -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()) diff --git a/Misc/NEWS b/Misc/NEWS index 55303a51af1..9dac6302ca2 100644 --- 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.