Skip to content

Commit 561c597

Browse files
authored
[3.7] bpo-39401: Avoid unsafe DLL load on Windows 7 and earlier (GH-18231) (GH-18232)
https://bugs.python.org/issue39401 Automerge-Triggered-By: @zooba
1 parent 194c7ae commit 561c597

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid unsafe load of ``api-ms-win-core-path-l1-1-0.dll`` at startup on Windows 7.

PC/getpathp.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ static void
245245
join(wchar_t *buffer, const wchar_t *stuff)
246246
{
247247
if (_PathCchCombineEx_Initialized == 0) {
248-
HMODULE pathapi = LoadLibraryW(L"api-ms-win-core-path-l1-1-0.dll");
248+
HMODULE pathapi = LoadLibraryExW(L"api-ms-win-core-path-l1-1-0.dll", NULL,
249+
LOAD_LIBRARY_SEARCH_SYSTEM32);
249250
if (pathapi) {
250251
_PathCchCombineEx = (PPathCchCombineEx)GetProcAddress(pathapi, "PathCchCombineEx");
251252
}
@@ -278,7 +279,8 @@ static _PyInitError canonicalize(wchar_t *buffer, const wchar_t *path)
278279
}
279280

280281
if (_PathCchCanonicalizeEx_Initialized == 0) {
281-
HMODULE pathapi = LoadLibraryW(L"api-ms-win-core-path-l1-1-0.dll");
282+
HMODULE pathapi = LoadLibraryExW(L"api-ms-win-core-path-l1-1-0.dll", NULL,
283+
LOAD_LIBRARY_SEARCH_SYSTEM32);
282284
if (pathapi) {
283285
_PathCchCanonicalizeEx = (PPathCchCanonicalizeEx)GetProcAddress(pathapi, "PathCchCanonicalizeEx");
284286
}

Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -3028,8 +3028,16 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
30283028
}
30293029
} else {
30303030
if (IsWindows7SP1OrGreater()) {
3031-
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Target OS is Windows 7 SP1 or later");
3032-
return;
3031+
HMODULE hKernel32 = GetModuleHandleW(L"kernel32");
3032+
if (hKernel32 && !GetProcAddress(hKernel32, "AddDllDirectory")) {
3033+
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows 7 SP1 without KB2533623");
3034+
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "KB2533623 update is required to continue.");
3035+
/* The "MissingSP1" error also specifies updates are required */
3036+
LocGetString(_wixLoc, L"#(loc.FailureWin7MissingSP1)", &pLocString);
3037+
} else {
3038+
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Target OS is Windows 7 SP1 or later");
3039+
return;
3040+
}
30333041
} else if (IsWindows7OrGreater()) {
30343042
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows 7 RTM");
30353043
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Service Pack 1 is required to continue installation");

0 commit comments

Comments
 (0)