Skip to content

Commit 51332c4

Browse files
authored
[3.6] bpo-39401: Avoid unsafe DLL load on Windows 7 and earlier (GH-18231) (GH-18233)
1 parent c563f40 commit 51332c4

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
@@ -224,7 +224,8 @@ static void
224224
join(wchar_t *buffer, const wchar_t *stuff)
225225
{
226226
if (_PathCchCombineEx_Initialized == 0) {
227-
HMODULE pathapi = LoadLibraryW(L"api-ms-win-core-path-l1-1-0.dll");
227+
HMODULE pathapi = LoadLibraryExW(L"api-ms-win-core-path-l1-1-0.dll", NULL,
228+
LOAD_LIBRARY_SEARCH_SYSTEM32);
228229
if (pathapi)
229230
_PathCchCombineEx = (PPathCchCombineEx)GetProcAddress(pathapi, "PathCchCombineEx");
230231
else
@@ -249,7 +250,8 @@ static PPathCchCanonicalizeEx _PathCchCanonicalizeEx;
249250
static void canonicalize(wchar_t *buffer, const wchar_t *path)
250251
{
251252
if (_PathCchCanonicalizeEx_Initialized == 0) {
252-
HMODULE pathapi = LoadLibraryW(L"api-ms-win-core-path-l1-1-0.dll");
253+
HMODULE pathapi = LoadLibraryExW(L"api-ms-win-core-path-l1-1-0.dll", NULL,
254+
LOAD_LIBRARY_SEARCH_SYSTEM32);
253255
if (pathapi) {
254256
_PathCchCanonicalizeEx = (PPathCchCanonicalizeEx)GetProcAddress(pathapi, "PathCchCanonicalizeEx");
255257
}

Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -3042,8 +3042,16 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
30423042
}
30433043
} else {
30443044
if (IsWindows7SP1OrGreater()) {
3045-
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Target OS is Windows 7 SP1 or later");
3046-
return;
3045+
HMODULE hKernel32 = GetModuleHandleW(L"kernel32");
3046+
if (hKernel32 && !GetProcAddress(hKernel32, "AddDllDirectory")) {
3047+
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows 7 SP1 without KB2533623");
3048+
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "KB2533623 update is required to continue.");
3049+
/* The "MissingSP1" error also specifies updates are required */
3050+
LocGetString(_wixLoc, L"#(loc.FailureWin7MissingSP1)", &pLocString);
3051+
} else {
3052+
BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Target OS is Windows 7 SP1 or later");
3053+
return;
3054+
}
30473055
} else if (IsWindows7OrGreater()) {
30483056
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Detected Windows 7 RTM");
30493057
BalLog(BOOTSTRAPPER_LOG_LEVEL_ERROR, "Service Pack 1 is required to continue installation");

0 commit comments

Comments
 (0)