Dmitry Timoshkov : crypt32: CryptFreeOIDFunctionAddress should not unload a registered module.
Module: wine Branch: master Commit: 3b1e55d09370926c4d73a386d2165a48a13b3875 URL: https://source.winehq.org/git/wine.git/?a=commit;h=3b1e55d09370926c4d73a386d... Author: Dmitry Timoshkov <dmitry(a)baikal.ru> Date: Wed Oct 31 15:43:08 2018 +0300 crypt32: CryptFreeOIDFunctionAddress should not unload a registered module. MSDN states that hModule passed to CryptInstallOIDFunctionAddress() should be used to prevent this module to be unloaded by CryptFreeOIDFunctionAddress in case the provider's DLL uses CryptRegisterOIDFunction to add its own entries. Signed-off-by: Dmitry Timoshkov <dmitry(a)baikal.ru> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- dlls/crypt32/oid.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/dlls/crypt32/oid.c b/dlls/crypt32/oid.c index d6c411c..6dc894e 100644 --- a/dlls/crypt32/oid.c +++ b/dlls/crypt32/oid.c @@ -59,6 +59,7 @@ struct OIDFunctionSet struct OIDFunction { + HMODULE hModule; DWORD encoding; CRYPT_OID_FUNC_ENTRY entry; struct list next; @@ -271,6 +272,7 @@ BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule, else func->entry.pszOID = rgFuncEntry[i].pszOID; func->entry.pvFuncAddr = rgFuncEntry[i].pvFuncAddr; + func->hModule = hModule; list_add_tail(&set->functions, &func->next); } else @@ -428,6 +430,38 @@ BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet, return ret; } +static BOOL is_module_registered(HMODULE hModule) +{ + struct OIDFunctionSet *set; + BOOL ret = FALSE; + + EnterCriticalSection(&funcSetCS); + + LIST_FOR_EACH_ENTRY(set, &funcSets, struct OIDFunctionSet, next) + { + struct OIDFunction *function; + + EnterCriticalSection(&set->cs); + + LIST_FOR_EACH_ENTRY(function, &set->functions, struct OIDFunction, next) + { + if (function->hModule == hModule) + { + ret = TRUE; + break; + } + } + + LeaveCriticalSection(&set->cs); + + if (ret) break; + } + + LeaveCriticalSection(&funcSetCS); + + return ret; +} + BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr, DWORD dwFlags) { @@ -441,9 +475,12 @@ BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr, { struct FuncAddr *addr = hFuncAddr; - CryptMemFree(addr->dllList); - FreeLibrary(addr->lib); - CryptMemFree(addr); + if (!is_module_registered(addr->lib)) + { + CryptMemFree(addr->dllList); + FreeLibrary(addr->lib); + CryptMemFree(addr); + } } return TRUE; }
participants (1)
-
Alexandre Julliard