]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46297: Fix interpreter crash on startup with multiple PythonPaths set in registry...
authorDaniel <daniel@tohka.us>
Fri, 7 Jan 2022 22:26:00 +0000 (00:26 +0200)
committerGitHub <noreply@github.com>
Fri, 7 Jan 2022 22:26:00 +0000 (22:26 +0000)
Lib/test/test_getpath.py
Misc/ACKS
Misc/NEWS.d/next/Core and Builtins/2022-01-07-22-13-59.bpo-46297.83ThTl.rst [new file with mode: 0644]
Modules/getpath.py

index 232b6805284354019967d6a633b3cf7df9b60ecb..1a336a4abcafdb18e6e62596821e34b4329fef1c 100644 (file)
@@ -734,12 +734,15 @@ class MockWinreg:
                 return n.removeprefix(prefix)
         raise OSError("end of enumeration")
 
-    def QueryValue(self, hkey):
+    def QueryValue(self, hkey, subkey):
         if verbose:
-            print(f"QueryValue({hkey})")
+            print(f"QueryValue({hkey}, {subkey})")
         hkey = hkey.casefold()
         if hkey not in self.open:
             raise RuntimeError("key is not open")
+        if subkey:
+            subkey = subkey.casefold()
+            hkey = f'{hkey}\\{subkey}'
         try:
             return self.keys[hkey]
         except KeyError:
index 8baaf7304b603c19de5d9221068d568a0a14a49e..7f2e94dfa615f1054caf6d39720a7f3e281653a3 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -400,6 +400,7 @@ Lars Damerow
 Evan Dandrea
 Eric Daniel
 Scott David Daniels
+Derzsi Dániel
 Lawrence D'Anna
 Ben Darnell
 Kushal Das
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-01-07-22-13-59.bpo-46297.83ThTl.rst b/Misc/NEWS.d/next/Core and Builtins/2022-01-07-22-13-59.bpo-46297.83ThTl.rst
new file mode 100644 (file)
index 0000000..558d239
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed an interpreter crash on bootup with multiple PythonPaths set in
+the Windows registry. Patch by Derzsi Dániel.
index 37d2ea03b0bbd2aa779aae36e16f4c5368cfd18d..6f2e0385577221b83edde9d94cb6fb6c83e7fb1d 100644 (file)
 # checked by looking for the BUILDDIR_TXT file, which contains the
 # relative path to the platlib dir. The executable_dir value is
 # derived from joining the VPATH preprocessor variable to the
-# directory containing pybuilddir.txt. If it is not found, the 
+# directory containing pybuilddir.txt. If it is not found, the
 # BUILD_LANDMARK file is found, which is part of the source tree.
 # prefix is then found by searching up for a file that should only
 # exist in the source tree, and the stdlib dir is set to prefix/Lib.
@@ -642,19 +642,12 @@ elif not pythonpath:
                     i = 0
                     while True:
                         try:
-                            keyname = winreg.EnumKey(key, i)
-                            subkey = winreg.OpenKeyEx(key, keyname)
-                            if not subkey:
-                                continue
-                            try:
-                                v = winreg.QueryValue(subkey)
-                            finally:
-                                winreg.CloseKey(subkey)
-                            if isinstance(v, str):
-                                pythonpath.append(v)
-                            i += 1
+                            v = winreg.QueryValue(key, winreg.EnumKey(key, i))
                         except OSError:
                             break
+                        if isinstance(v, str):
+                            pythonpath.append(v)
+                        i += 1
                 finally:
                     winreg.CloseKey(key)
             except OSError: