]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-95359: Fix py.exe launcher handling of per-user py.ini and command names (GH-95399)
authorSteve Dower <steve.dower@python.org>
Thu, 28 Jul 2022 20:11:17 +0000 (21:11 +0100)
committerGitHub <noreply@github.com>
Thu, 28 Jul 2022 20:11:17 +0000 (21:11 +0100)
Lib/test/test_launcher.py
Misc/NEWS.d/next/Windows/2022-07-28-20-21-38.gh-issue-95359.ywMrgu.rst [new file with mode: 0644]
PC/launcher2.c

index b4009a99a705afd652c4a2741a6c7ee4b2b43e57..c8ea4f62170eac97ced1d14cf93e89322ce275bb 100644 (file)
@@ -69,7 +69,7 @@ TEST_PY_ENV = dict(
 
 TEST_PY_COMMANDS = "\n".join([
     "[defaults]",
-    *[f"{k.lower()}={v}" for k, v in TEST_PY_ENV.items()]
+    *[f"{k[3:].lower()}={v}" for k, v in TEST_PY_ENV.items()]
 ])
 
 
diff --git a/Misc/NEWS.d/next/Windows/2022-07-28-20-21-38.gh-issue-95359.ywMrgu.rst b/Misc/NEWS.d/next/Windows/2022-07-28-20-21-38.gh-issue-95359.ywMrgu.rst
new file mode 100644 (file)
index 0000000..513a2be
--- /dev/null
@@ -0,0 +1,3 @@
+Fix :ref:`launcher` handling of :file:`py.ini` commands (it was incorrectly
+expecting a ``py_`` prefix on keys) and crashes when reading per-user
+configuration file.
index 31b5617771e9b973b26b0eed13ffb5e7b0b2c035..033218ee2f408e7f0e0c88758c4191db3da7e3b1 100644 (file)
@@ -761,7 +761,7 @@ _readIni(const wchar_t *section, const wchar_t *settingName, wchar_t *buffer, in
         n = GetPrivateProfileStringW(section, settingName, NULL, buffer, bufferLength, iniPath);
         if (n) {
             debug(L"# Found %s in %s\n", settingName, iniPath);
-            return true;
+            return n;
         } else if (GetLastError() == ERROR_FILE_NOT_FOUND) {
             debug(L"# Did not find file %s\n", iniPath);
         } else {
@@ -946,13 +946,17 @@ checkDefaults(SearchInfo *search)
 
     // If tag is only a major version number, expand it from the environment
     // or an ini file
-    const wchar_t *settingName = NULL;
+    const wchar_t *iniSettingName = NULL;
+    const wchar_t *envSettingName = NULL;
     if (!search->tag || !search->tagLength) {
-        settingName = L"py_python";
+        iniSettingName = L"python";
+        envSettingName = L"py_python";
     } else if (0 == wcsncmp(search->tag, L"3", search->tagLength)) {
-        settingName = L"py_python3";
+        iniSettingName = L"python3";
+        envSettingName = L"py_python3";
     } else if (0 == wcsncmp(search->tag, L"2", search->tagLength)) {
-        settingName = L"py_python2";
+        iniSettingName = L"python2";
+        envSettingName = L"py_python2";
     } else {
         debug(L"# Cannot select defaults for tag '%.*s'\n", search->tagLength, search->tag);
         return 0;
@@ -960,11 +964,11 @@ checkDefaults(SearchInfo *search)
 
     // First, try to read an environment variable
     wchar_t buffer[MAXLEN];
-    int n = GetEnvironmentVariableW(settingName, buffer, MAXLEN);
+    int n = GetEnvironmentVariableW(envSettingName, buffer, MAXLEN);
 
     // If none found, check in our two .ini files instead
     if (!n) {
-        n = _readIni(L"defaults", settingName, buffer, MAXLEN);
+        n = _readIni(L"defaults", iniSettingName, buffer, MAXLEN);
     }
 
     if (n) {