From 5c8aa89163fabc0496c96deeabd3775b2c9116cc Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Mon, 14 Jan 2008 11:15:35 -0800 Subject: [PATCH] crypt32: Fix race condition in loading default provider. --- dlls/crypt32/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dlls/crypt32/main.c b/dlls/crypt32/main.c index fa90ee05726..922dd1955a7 100644 --- a/dlls/crypt32/main.c +++ b/dlls/crypt32/main.c @@ -59,8 +59,16 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) HCRYPTPROV CRYPT_GetDefaultProvider(void) { if (!hDefProv) - CryptAcquireContextW(&hDefProv, NULL, MS_ENHANCED_PROV_W, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); + { + HCRYPTPROV prov; + + CryptAcquireContextW(&prov, NULL, MS_ENHANCED_PROV_W, PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT); + InterlockedCompareExchangePointer((PVOID *)&hDefProv, (PVOID)prov, + NULL); + if (hDefProv != prov) + CryptReleaseContext(prov, 0); + } return hDefProv; }