mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
bpo-29778: Ensure python3.dll is loaded from correct locations when Python is embedded (GH-21297)
Also enables using debug build of `python3_d.dll`
Reference: CVE-2020-15523
(cherry picked from commit dcbaa1b49c)
Co-authored-by: Steve Dower <steve.dower@python.org>
This commit is contained in:
parent
97558d6b08
commit
4981fe36c7
8 changed files with 150 additions and 137 deletions
|
|
@ -18,10 +18,53 @@
|
|||
#include "pycore_gc.h" // PyGC_Head
|
||||
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
#include <windows.h>
|
||||
|
||||
static int
|
||||
_add_windows_config(PyObject *configs)
|
||||
{
|
||||
HMODULE hPython3;
|
||||
wchar_t py3path[MAX_PATH];
|
||||
PyObject *dict = PyDict_New();
|
||||
PyObject *obj = NULL;
|
||||
if (!dict) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
hPython3 = GetModuleHandleW(PY3_DLLNAME);
|
||||
if (hPython3 && GetModuleFileNameW(hPython3, py3path, MAX_PATH)) {
|
||||
obj = PyUnicode_FromWideChar(py3path, -1);
|
||||
} else {
|
||||
obj = Py_None;
|
||||
Py_INCREF(obj);
|
||||
}
|
||||
if (obj &&
|
||||
!PyDict_SetItemString(dict, "python3_dll", obj) &&
|
||||
!PyDict_SetItemString(configs, "windows", dict)) {
|
||||
Py_DECREF(obj);
|
||||
Py_DECREF(dict);
|
||||
return 0;
|
||||
}
|
||||
Py_DECREF(obj);
|
||||
Py_DECREF(dict);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static PyObject *
|
||||
get_configs(PyObject *self, PyObject *Py_UNUSED(args))
|
||||
{
|
||||
return _Py_GetConfigsAsDict();
|
||||
PyObject *dict = _Py_GetConfigsAsDict();
|
||||
#ifdef MS_WINDOWS
|
||||
if (dict) {
|
||||
if (_add_windows_config(dict) < 0) {
|
||||
Py_CLEAR(dict);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return dict;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue