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.
diff --git a/Lib/glob.py b/Lib/glob.py
index 3431a69..00f867f 100644
--- a/Lib/glob.py
+++ b/Lib/glob.py
@@ -28,7 +28,10 @@
     if not dirname:
         yield from glob1(None, basename)
         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]
diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py
index 806f26b..8972b8f 100644
--- a/Lib/test/test_glob.py
+++ b/Lib/test/test_glob.py
@@ -4,6 +4,7 @@
 import glob
 import os
 import shutil
+import sys
 
 
 class GlobTests(unittest.TestCase):
@@ -110,6 +111,18 @@
         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)
diff --git a/Misc/NEWS b/Misc/NEWS
index 6be851e..fcbfb9f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -167,6 +167,10 @@
 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 #15783: Except for the number methods, the C version of decimal now
   supports all None default values present in decimal.py. These values were
   largely undocumented.