mirror of
https://github.com/python/cpython.git
synced 2025-08-24 10:45:53 +00:00
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
This commit is contained in:
commit
1add96f1b6
3 changed files with 14 additions and 1 deletions
|
@ -1235,7 +1235,7 @@ class Path(PurePath):
|
||||||
if not exist_ok or not self.is_dir():
|
if not exist_ok or not self.is_dir():
|
||||||
raise
|
raise
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != ENOENT:
|
if e.errno != ENOENT or self.parent == self:
|
||||||
raise
|
raise
|
||||||
self.parent.mkdir(parents=True)
|
self.parent.mkdir(parents=True)
|
||||||
self._accessor.mkdir(self, mode)
|
self._accessor.mkdir(self, mode)
|
||||||
|
|
|
@ -1776,6 +1776,17 @@ class _BasePathTest(object):
|
||||||
self.assertTrue(p.exists())
|
self.assertTrue(p.exists())
|
||||||
self.assertEqual(p.stat().st_ctime, st_ctime_first)
|
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):
|
def test_mkdir_with_child_file(self):
|
||||||
p = self.cls(BASE, 'dirB', 'fileB')
|
p = self.cls(BASE, 'dirB', 'fileB')
|
||||||
self.assertTrue(p.exists())
|
self.assertTrue(p.exists())
|
||||||
|
|
|
@ -55,6 +55,8 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
|
||||||
|
|
||||||
- Issue #29444: Fixed out-of-bounds buffer access in the group() method of
|
- Issue #29444: Fixed out-of-bounds buffer access in the group() method of
|
||||||
the match object. Based on patch by WGH.
|
the match object. Based on patch by WGH.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue