Commit 124ee8b1 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #16626: Fix infinite recursion in glob.glob() on Windows when the...

Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern contains a wildcard in the drive or UNC path.
Patch by Serhiy Storchaka.
parent 646c7b50
...@@ -38,7 +38,10 @@ def iglob(pathname): ...@@ -38,7 +38,10 @@ def iglob(pathname):
for name in glob1(os.curdir, basename): for name in glob1(os.curdir, basename):
yield name yield name
return return
if has_magic(dirname): # `os.path.split()` returns the argument itself as a dirname if it is a
# drive or UNC path. Prevent an infinite recursion if a drive or UNC path
# contains magic characters (i.e. r'\\?\C:').
if dirname != pathname and has_magic(dirname):
dirs = iglob(dirname) dirs = iglob(dirname)
else: else:
dirs = [dirname] dirs = [dirname]
......
...@@ -3,6 +3,7 @@ from test.test_support import run_unittest, TESTFN ...@@ -3,6 +3,7 @@ from test.test_support import run_unittest, TESTFN
import glob import glob
import os import os
import shutil import shutil
import sys
class GlobTests(unittest.TestCase): class GlobTests(unittest.TestCase):
...@@ -110,6 +111,14 @@ class GlobTests(unittest.TestCase): ...@@ -110,6 +111,14 @@ class GlobTests(unittest.TestCase):
eq(self.glob('sym1'), [self.norm('sym1')]) eq(self.glob('sym1'), [self.norm('sym1')])
eq(self.glob('sym2'), [self.norm('sym2')]) eq(self.glob('sym2'), [self.norm('sym2')])
@unittest.skipUnless(sys.platform == "win32", "Win32 specific test")
def test_glob_magic_in_drive(self):
eq = self.assertSequencesEqual_noorder
eq(glob.glob('*:'), [])
eq(glob.glob(u'*:'), [])
eq(glob.glob('?:'), [])
eq(glob.glob(u'?:'), [])
def test_main(): def test_main():
run_unittest(GlobTests) run_unittest(GlobTests)
......
...@@ -160,6 +160,10 @@ Core and Builtins ...@@ -160,6 +160,10 @@ Core and Builtins
Library Library
------- -------
- Issue #16626: Fix infinite recursion in glob.glob() on Windows when the
pattern contains a wildcard in the drive or UNC path. Patch by Serhiy
Storchaka.
- Issue #16298: In HTTPResponse.read(), close the socket when there is no - Issue #16298: In HTTPResponse.read(), close the socket when there is no
Content-Length and the incoming stream is finished. Patch by Eran Content-Length and the incoming stream is finished. Patch by Eran
Rundstein. Rundstein.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment