summaryrefslogtreecommitdiff
path: root/src/modules/netlib/netlibsecurity.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-05-22 12:53:41 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-05-22 12:53:41 +0000
commit7cfd634814762a3cd8a22fce9a4ec6d47bb8f536 (patch)
tree2f977cf59229d2d30bff2b9f969e2211fffae6ab /src/modules/netlib/netlibsecurity.cpp
parentb280d2eae93fb22b4fdb45218d8a06287a97030e (diff)
fix for a crash inside http request destruction
git-svn-id: http://svn.miranda-ng.org/main/trunk@13754 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/netlib/netlibsecurity.cpp')
-rw-r--r--src/modules/netlib/netlibsecurity.cpp30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/modules/netlib/netlibsecurity.cpp b/src/modules/netlib/netlibsecurity.cpp
index 10a322453d..6533a1fa5f 100644
--- a/src/modules/netlib/netlibsecurity.cpp
+++ b/src/modules/netlib/netlibsecurity.cpp
@@ -61,7 +61,7 @@ struct NtlmType2packet
};
static unsigned secCnt = 0, ntlmCnt = 0;
-static HANDLE hSecMutex;
+static mir_cs csSec;
static void ReportSecError(SECURITY_STATUS scRet, int line)
{
@@ -116,7 +116,7 @@ HANDLE NetlibInitSecurityProvider(const TCHAR* szProvider, const TCHAR* szPrinci
return hNtlm;
}
- WaitForSingleObject(hSecMutex, INFINITE);
+ mir_cslock lck(csSec);
if (secCnt == 0) {
LoadSecurityLibrary();
@@ -143,8 +143,6 @@ HANDLE NetlibInitSecurityProvider(const TCHAR* szProvider, const TCHAR* szPrinci
ntlmCnt++;
}
}
-
- ReleaseMutex(hSecMutex);
return hSecurity;
}
@@ -158,24 +156,23 @@ void NetlibDestroySecurityProvider(HANDLE hSecurity)
if (hSecurity == NULL)
return;
- WaitForSingleObject(hSecMutex, INFINITE);
+ mir_cslock lck(csSec);
if (ntlmCnt != 0) {
NtlmHandleType* hNtlm = (NtlmHandleType*)hSecurity;
- if (SecIsValidHandle(&hNtlm->hClientContext)) g_pSSPI->DeleteSecurityContext(&hNtlm->hClientContext);
- if (SecIsValidHandle(&hNtlm->hClientCredential)) g_pSSPI->FreeCredentialsHandle(&hNtlm->hClientCredential);
- mir_free(hNtlm->szProvider);
- mir_free(hNtlm->szPrincipal);
+ if (hNtlm != NULL) {
+ if (SecIsValidHandle(&hNtlm->hClientContext)) g_pSSPI->DeleteSecurityContext(&hNtlm->hClientContext);
+ if (SecIsValidHandle(&hNtlm->hClientCredential)) g_pSSPI->FreeCredentialsHandle(&hNtlm->hClientCredential);
+ mir_free(hNtlm->szProvider);
+ mir_free(hNtlm->szPrincipal);
+ mir_free(hNtlm);
+ }
--ntlmCnt;
-
- mir_free(hNtlm);
}
if (secCnt && --secCnt == 0)
FreeSecurityLibrary();
-
- ReleaseMutex(hSecMutex);
}
char* CompleteGssapi(HANDLE hSecurity, unsigned char *szChallenge, unsigned chlsz)
@@ -458,16 +455,9 @@ static INT_PTR NtlmCreateResponseService2(WPARAM wParam, LPARAM lParam)
void NetlibSecurityInit(void)
{
- hSecMutex = CreateMutex(NULL, FALSE, NULL);
-
CreateServiceFunction(MS_NETLIB_INITSECURITYPROVIDER, InitSecurityProviderService);
CreateServiceFunction(MS_NETLIB_INITSECURITYPROVIDER2, InitSecurityProviderService2);
CreateServiceFunction(MS_NETLIB_DESTROYSECURITYPROVIDER, DestroySecurityProviderService);
CreateServiceFunction(MS_NETLIB_NTLMCREATERESPONSE, NtlmCreateResponseService);
CreateServiceFunction(MS_NETLIB_NTLMCREATERESPONSE2, NtlmCreateResponseService2);
}
-
-void NetlibSecurityDestroy(void)
-{
- CloseHandle(hSecMutex);
-}