diff options
author | Thomas Heller <theller@ctypes.org> | 2004-07-02 08:53:57 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2004-07-02 08:53:57 (GMT) |
commit | 1df04617b7e8678420dfefa0319fea9fab84af53 (patch) | |
tree | 59024130db8a9040fc0b361f2f96ae2a9a262c75 /Python | |
parent | 32b8f8052a0cf62fe8f9f3dbc539a0f1b3065896 (diff) | |
download | cpython-1df04617b7e8678420dfefa0319fea9fab84af53.zip cpython-1df04617b7e8678420dfefa0319fea9fab84af53.tar.gz cpython-1df04617b7e8678420dfefa0319fea9fab84af53.tar.bz2 |
When importing an extension on Windows, the code reads the PE 'import
table' of the dll, to make sure that the dll really was build for the
correct Python version. It does this by looking for an entry
'pythonXY.dll' (X.Y is the Python version number).
The code now checks the size of the dll's import table before reading
entries from it. Before this patch, the code crashed trying to read
the import table when the size was zero (as in Win2k's wmi.dll, for
example).
Look for imports of 'pythonXY_d.dll' in a debug build instead of
'pythonXY.dll'.
Fixes SF 951851: Crash when reading "import table" of certain windows dlls.
Already backported to the 2.3 branch.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/dynload_win.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Python/dynload_win.c b/Python/dynload_win.c index b9d5c8e..6e8f822 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -116,6 +116,10 @@ static char *GetPythonImport (HINSTANCE hModule) string constant holding the import name is located. */ if (DWORD_AT(dllbase + opt_offset + num_dict_off) >= 2) { + /* We have at least 2 tables - the import table is the second + one. But still it may be that the table size is zero */ + if (0 == DWORD_AT(dllbase + opt_offset + import_off + sizeof(DWORD))) + return NULL; import_data = dllbase + DWORD_AT(dllbase + opt_offset + import_off); @@ -128,7 +132,11 @@ static char *GetPythonImport (HINSTANCE hModule) /* Ensure python prefix is followed only by numbers to the end of the basename */ pch = import_name + 6; +#ifdef _DEBUG + while (*pch && pch[0] != '_' && pch[1] != 'd' && pch[2] != '.') { +#else while (*pch && *pch != '.') { +#endif if (*pch >= '0' && *pch <= '9') { pch++; } else { @@ -221,7 +229,11 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, } else { char buffer[256]; +#ifdef _DEBUG + PyOS_snprintf(buffer, sizeof(buffer), "python%d%d_d.dll", +#else PyOS_snprintf(buffer, sizeof(buffer), "python%d%d.dll", +#endif PY_MAJOR_VERSION,PY_MINOR_VERSION); import_python = GetPythonImport(hDLL); |