changeset: 106423:09c018897fb3 parent: 106420:476b0fa34db4 parent: 106422:3de58a54ed98 user: Steve Dower date: Sat Feb 04 14:56:57 2017 -0800 files: Misc/NEWS description: Issue #29416: Prevent infinite loop in pathlib.Path.mkdir diff -r 476b0fa34db4 -r 09c018897fb3 Lib/pathlib.py --- a/Lib/pathlib.py Sat Feb 04 22:57:44 2017 +0200 +++ b/Lib/pathlib.py Sat Feb 04 14:56:57 2017 -0800 @@ -1235,7 +1235,7 @@ 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 -r 476b0fa34db4 -r 09c018897fb3 Lib/test/test_pathlib.py --- a/Lib/test/test_pathlib.py Sat Feb 04 22:57:44 2017 +0200 +++ b/Lib/test/test_pathlib.py Sat Feb 04 14:56:57 2017 -0800 @@ -1776,6 +1776,17 @@ 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 -r 476b0fa34db4 -r 09c018897fb3 Misc/NEWS --- a/Misc/NEWS Sat Feb 04 22:57:44 2017 +0200 +++ b/Misc/NEWS Sat Feb 04 14:56:57 2017 -0800 @@ -223,6 +223,8 @@ 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.