]> granicus.if.org Git - python/commitdiff
Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern conta...
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 16 Dec 2012 12:49:37 +0000 (13:49 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 16 Dec 2012 12:49:37 +0000 (13:49 +0100)
Patch by Serhiy Storchaka.

Lib/glob.py
Lib/test/test_glob.py
Misc/NEWS

index 36d493d7a8032656ce49e1531ab1e9508564220d..7279244aa9ab2735f2bc47829fc3f62af9327eff 100644 (file)
@@ -29,7 +29,10 @@ def iglob(pathname):
         for name in glob1(None, basename):
             yield name
         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)
     else:
         dirs = [dirname]
index 711369e289b35fbd990d28a1f8550d40f90b4572..0083a70e7a48cffa900d567227782fe685990bbb 100644 (file)
@@ -3,6 +3,7 @@ from test.support import run_unittest, TESTFN, skip_unless_symlink, can_symlink
 import glob
 import os
 import shutil
+import sys
 
 
 class GlobTests(unittest.TestCase):
@@ -110,6 +111,18 @@ class GlobTests(unittest.TestCase):
         eq(self.glob('sym1'), [self.norm('sym1')])
         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(b'*:'), [])
+        eq(glob.glob('?:'), [])
+        eq(glob.glob(b'?:'), [])
+        eq(glob.glob('\\\\?\\c:\\'), ['\\\\?\\c:\\'])
+        eq(glob.glob(b'\\\\?\\c:\\'), [b'\\\\?\\c:\\'])
+        eq(glob.glob('\\\\*\\*\\'), [])
+        eq(glob.glob(b'\\\\*\\*\\'), [])
+
 
 def test_main():
     run_unittest(GlobTests)
index c5288f76e6149d54aa4d8e64d1cabe75e98eee1f..73f23982b3e4a7f8113a3470bc8b9aead7a9c6a4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -179,6 +179,10 @@ Core and Builtins
 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
   Content-Length and the incoming stream is finished.  Patch by Eran
   Rundstein.