mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	gh-95359: Fix py.exe launcher handling of per-user py.ini and command names (GH-95399)
This commit is contained in:
		
							parent
							
								
									a1daf6e5cc
								
							
						
					
					
						commit
						38bb2068fe
					
				
					 3 changed files with 15 additions and 8 deletions
				
			
		| 
						 | 
					@ -69,7 +69,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_PY_COMMANDS = "\n".join([
 | 
					TEST_PY_COMMANDS = "\n".join([
 | 
				
			||||||
    "[defaults]",
 | 
					    "[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()]
 | 
				
			||||||
])
 | 
					])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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.
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
					        n = GetPrivateProfileStringW(section, settingName, NULL, buffer, bufferLength, iniPath);
 | 
				
			||||||
        if (n) {
 | 
					        if (n) {
 | 
				
			||||||
            debug(L"# Found %s in %s\n", settingName, iniPath);
 | 
					            debug(L"# Found %s in %s\n", settingName, iniPath);
 | 
				
			||||||
            return true;
 | 
					            return n;
 | 
				
			||||||
        } else if (GetLastError() == ERROR_FILE_NOT_FOUND) {
 | 
					        } else if (GetLastError() == ERROR_FILE_NOT_FOUND) {
 | 
				
			||||||
            debug(L"# Did not find file %s\n", iniPath);
 | 
					            debug(L"# Did not find file %s\n", iniPath);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
| 
						 | 
					@ -946,13 +946,17 @@ checkDefaults(SearchInfo *search)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // If tag is only a major version number, expand it from the environment
 | 
					    // If tag is only a major version number, expand it from the environment
 | 
				
			||||||
    // or an ini file
 | 
					    // or an ini file
 | 
				
			||||||
    const wchar_t *settingName = NULL;
 | 
					    const wchar_t *iniSettingName = NULL;
 | 
				
			||||||
 | 
					    const wchar_t *envSettingName = NULL;
 | 
				
			||||||
    if (!search->tag || !search->tagLength) {
 | 
					    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)) {
 | 
					    } 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)) {
 | 
					    } else if (0 == wcsncmp(search->tag, L"2", search->tagLength)) {
 | 
				
			||||||
        settingName = L"py_python2";
 | 
					        iniSettingName = L"python2";
 | 
				
			||||||
 | 
					        envSettingName = L"py_python2";
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        debug(L"# Cannot select defaults for tag '%.*s'\n", search->tagLength, search->tag);
 | 
					        debug(L"# Cannot select defaults for tag '%.*s'\n", search->tagLength, search->tag);
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
| 
						 | 
					@ -960,11 +964,11 @@ checkDefaults(SearchInfo *search)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // First, try to read an environment variable
 | 
					    // First, try to read an environment variable
 | 
				
			||||||
    wchar_t buffer[MAXLEN];
 | 
					    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 none found, check in our two .ini files instead
 | 
				
			||||||
    if (!n) {
 | 
					    if (!n) {
 | 
				
			||||||
        n = _readIni(L"defaults", settingName, buffer, MAXLEN);
 | 
					        n = _readIni(L"defaults", iniSettingName, buffer, MAXLEN);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (n) {
 | 
					    if (n) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue