Commit 6db69d02 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

wintrust: Use CRT allocation functions.

parent 537bcadb
......@@ -92,10 +92,8 @@ static void WINTRUST_InitRegStructs(void)
{
#define WINTRUST_INITREGENTRY( action, dllname, functionname ) \
action.cbStruct = sizeof(CRYPT_TRUST_REG_ENTRY); \
action.pwszDLLName = WINTRUST_Alloc(sizeof(dllname)); \
lstrcpyW(action.pwszDLLName, dllname); \
action.pwszFunctionName = WINTRUST_Alloc(sizeof(functionname)); \
lstrcpyW(action.pwszFunctionName, functionname);
action.pwszDLLName = wcsdup(dllname); \
action.pwszFunctionName = wcsdup(functionname);
WINTRUST_INITREGENTRY(SoftpubInitialization, SP_POLICY_PROVIDER_DLL_NAME, SP_INIT_FUNCTION)
WINTRUST_INITREGENTRY(SoftpubMessage, SP_POLICY_PROVIDER_DLL_NAME, SP_OBJTRUST_FUNCTION)
......@@ -128,8 +126,8 @@ static void WINTRUST_InitRegStructs(void)
static void WINTRUST_FreeRegStructs(void)
{
#define WINTRUST_FREEREGENTRY( action ) \
WINTRUST_Free(action.pwszDLLName); \
WINTRUST_Free(action.pwszFunctionName);
free(action.pwszDLLName); \
free(action.pwszFunctionName);
WINTRUST_FREEREGENTRY(SoftpubInitialization);
WINTRUST_FREEREGENTRY(SoftpubMessage);
......@@ -383,11 +381,11 @@ static LONG WINTRUST_WriteSingleUsageEntry(LPCSTR OID,
/* Turn OID into a wide-character string */
Len = MultiByteToWideChar( CP_ACP, 0, OID, -1, NULL, 0 );
OIDW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
OIDW = malloc( Len * sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, OID, -1, OIDW, Len );
/* Allocate the needed space for UsageKey */
UsageKey = WINTRUST_Alloc((lstrlenW(Trust) + lstrlenW(Usages) + Len) * sizeof(WCHAR));
UsageKey = malloc((wcslen(Trust) + wcslen(Usages) + Len) * sizeof(WCHAR));
/* Create the key string */
lstrcpyW(UsageKey, Trust);
lstrcatW(UsageKey, Usages);
......@@ -402,8 +400,8 @@ static LONG WINTRUST_WriteSingleUsageEntry(LPCSTR OID,
}
RegCloseKey(Key);
WINTRUST_Free(OIDW);
WINTRUST_Free(UsageKey);
free(OIDW);
free(UsageKey);
return Res;
}
......@@ -601,8 +599,7 @@ static BOOL WINTRUST_RegisterHttpsProv(void)
ProvInfo.sTestPolicyProvider = NullCTRE; /* No diagnostic policy */
ProvInfo.sCleanupProvider = SoftpubCleanup;
DefUsage.pwszDllName = WINTRUST_Alloc(sizeof(SP_POLICY_PROVIDER_DLL_NAME));
lstrcpyW(DefUsage.pwszDllName, SP_POLICY_PROVIDER_DLL_NAME);
DefUsage.pwszDllName = wcsdup(SP_POLICY_PROVIDER_DLL_NAME);
if (!WintrustAddDefaultForUsage(szOID_PKIX_KP_SERVER_AUTH, &DefUsage))
RegisteredOK = FALSE;
......@@ -613,7 +610,7 @@ static BOOL WINTRUST_RegisterHttpsProv(void)
if (!WintrustAddDefaultForUsage(szOID_SGC_NETSCAPE, &DefUsage))
RegisteredOK = FALSE;
WINTRUST_Free(DefUsage.pwszDllName);
free(DefUsage.pwszDllName);
if (!WintrustAddActionID(&ProvGUID, 0, &ProvInfo))
RegisteredOK = FALSE;
......@@ -762,26 +759,26 @@ BOOL WINAPI WintrustAddDefaultForUsage(const char *pszUsageOID,
WCHAR* CallbackW;
Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, NULL, 0 );
CallbackW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
CallbackW = malloc( Len * sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszLoadCallbackDataFunctionName, -1, CallbackW, Len );
Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBAlloc, CallbackW);
if (Res != ERROR_SUCCESS) WriteUsageError = Res;
WINTRUST_Free(CallbackW);
free(CallbackW);
}
if (psDefUsage->pwszFreeCallbackDataFunctionName)
{
WCHAR* CallbackW;
Len = MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, NULL, 0 );
CallbackW = WINTRUST_Alloc( Len * sizeof(WCHAR) );
CallbackW = malloc( Len * sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, psDefUsage->pwszFreeCallbackDataFunctionName, -1, CallbackW, Len );
Res = WINTRUST_WriteSingleUsageEntry(pszUsageOID, CBFree, CallbackW);
if (Res != ERROR_SUCCESS) WriteUsageError = Res;
WINTRUST_Free(CallbackW);
free(CallbackW);
}
WINTRUST_Guid2Wstr(psDefUsage->pgActionID, GuidString);
......@@ -852,6 +849,16 @@ static struct provider_cache_entry
*provider_cache;
static unsigned int provider_cache_size;
static void * WINAPI WINTRUST_Alloc(DWORD cb)
{
return calloc(1, cb);
}
static void WINAPI WINTRUST_Free(void *p)
{
free(p);
}
/***********************************************************************
* WintrustLoadFunctionPointers (WINTRUST.@)
*/
......@@ -951,10 +958,9 @@ static BOOL WINTRUST_SIPPAddProvider(GUID* Subject, WCHAR* MagicNumber)
/* Clear and initialize the structure */
memset(&NewProv, 0, sizeof(SIP_ADD_NEWPROVIDER));
NewProv.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
NewProv.pwszDLLFileName = WINTRUST_Alloc(sizeof(SP_POLICY_PROVIDER_DLL_NAME));
NewProv.pwszDLLFileName = wcsdup(SP_POLICY_PROVIDER_DLL_NAME);
/* Fill the structure */
NewProv.pgSubject = Subject;
lstrcpyW(NewProv.pwszDLLFileName, SP_POLICY_PROVIDER_DLL_NAME);
NewProv.pwszMagicNumber = MagicNumber;
NewProv.pwszIsFunctionName = NULL;
NewProv.pwszGetFuncName = CryptSIPGetSignedDataMsg;
......@@ -967,7 +973,7 @@ static BOOL WINTRUST_SIPPAddProvider(GUID* Subject, WCHAR* MagicNumber)
Ret = CryptSIPAddProvider(&NewProv);
WINTRUST_Free(NewProv.pwszDLLFileName);
free(NewProv.pwszDLLFileName);
return Ret;
}
......
......@@ -213,7 +213,7 @@ static BOOL hash_file_data( HANDLE file, DWORD start, DWORD end, HCRYPTHASH hash
{
DWORD bytes_read, size = end - start;
DWORD buffer_size = min( size, 1024*1024 );
BYTE *buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size );
BYTE *buffer = malloc( buffer_size );
if (!buffer) return FALSE;
SetFilePointer( file, start, NULL, FILE_BEGIN );
......@@ -224,7 +224,7 @@ static BOOL hash_file_data( HANDLE file, DWORD start, DWORD end, HCRYPTHASH hash
if (!CryptHashData( hash, buffer, bytes_read, 0 )) break;
size -= bytes_read;
}
HeapFree( GetProcessHeap(), 0, buffer );
free( buffer );
return !size;
}
......
......@@ -36,24 +36,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
/* Utility functions */
void * WINAPI WINTRUST_Alloc(DWORD cb)
{
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb);
}
static void* WINTRUST_ReAlloc(void *ptr, DWORD cb) __WINE_ALLOC_SIZE(2);
static void* WINTRUST_ReAlloc(void *ptr, DWORD cb)
{
return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ptr, cb);
}
void WINAPI WINTRUST_Free(void *p)
{
HeapFree(GetProcessHeap(), 0, p);
}
/***********************************************************************
* TrustIsCertificateSelfSigned (WINTRUST.@)
*/
......@@ -200,23 +182,22 @@ static CRYPT_PROVIDER_DATA *WINTRUST_AllocateProviderData(void)
{
CRYPT_PROVIDER_DATA *provData;
provData = WINTRUST_Alloc(sizeof(CRYPT_PROVIDER_DATA));
provData = calloc(1, sizeof(CRYPT_PROVIDER_DATA));
if (!provData)
goto oom;
provData->cbStruct = sizeof(CRYPT_PROVIDER_DATA);
provData->padwTrustStepErrors =
WINTRUST_Alloc(TRUSTERROR_MAX_STEPS * sizeof(DWORD));
provData->padwTrustStepErrors = calloc(TRUSTERROR_MAX_STEPS, sizeof(DWORD));
if (!provData->padwTrustStepErrors)
goto oom;
provData->cdwTrustStepErrors = TRUSTERROR_MAX_STEPS;
provData->pPDSip = WINTRUST_Alloc(sizeof(PROVDATA_SIP));
provData->pPDSip = calloc(1, sizeof(PROVDATA_SIP));
if (!provData->pPDSip)
goto oom;
provData->pPDSip->cbStruct = sizeof(PROVDATA_SIP);
provData->psPfns = WINTRUST_Alloc(sizeof(CRYPT_PROVIDER_FUNCTIONS));
provData->psPfns = calloc(1, sizeof(CRYPT_PROVIDER_FUNCTIONS));
if (!provData->psPfns)
goto oom;
provData->psPfns->cbStruct = sizeof(CRYPT_PROVIDER_FUNCTIONS);
......@@ -225,10 +206,10 @@ static CRYPT_PROVIDER_DATA *WINTRUST_AllocateProviderData(void)
oom:
if (provData)
{
WINTRUST_Free(provData->padwTrustStepErrors);
WINTRUST_Free(provData->pPDSip);
WINTRUST_Free(provData->psPfns);
WINTRUST_Free(provData);
free(provData->padwTrustStepErrors);
free(provData->pPDSip);
free(provData->psPfns);
free(provData);
}
return NULL;
}
......@@ -309,10 +290,10 @@ static LONG WINTRUST_DefaultVerify(HWND hwnd, GUID *actionID,
goto done;
error:
WINTRUST_Free(provData->padwTrustStepErrors);
WINTRUST_Free(provData->pPDSip);
WINTRUST_Free(provData->psPfns);
WINTRUST_Free(provData);
free(provData->padwTrustStepErrors);
free(provData->pPDSip);
free(provData->psPfns);
free(provData);
done:
TRACE("returning %08lx\n", err);
......@@ -332,10 +313,10 @@ static LONG WINTRUST_DefaultClose(HWND hwnd, GUID *actionID,
if (provData->psPfns->pfnCleanupPolicy)
err = provData->psPfns->pfnCleanupPolicy(provData);
WINTRUST_Free(provData->padwTrustStepErrors);
WINTRUST_Free(provData->pPDSip);
WINTRUST_Free(provData->psPfns);
WINTRUST_Free(provData);
free(provData->padwTrustStepErrors);
free(provData->pPDSip);
free(provData->psPfns);
free(provData);
data->hWVTStateData = NULL;
}
TRACE("returning %08lx\n", err);
......@@ -500,10 +481,10 @@ static LONG WINTRUST_CertVerify(HWND hwnd, GUID *actionID,
goto done;
error:
WINTRUST_Free(provData->padwTrustStepErrors);
WINTRUST_Free(provData->pPDSip);
WINTRUST_Free(provData->psPfns);
WINTRUST_Free(provData);
free(provData->padwTrustStepErrors);
free(provData->pPDSip);
free(provData->psPfns);
free(provData);
done:
TRACE("returning %08lx\n", err);
......@@ -852,7 +833,7 @@ static BOOL WINAPI WINTRUST_enumUsages(PCCRYPT_OID_INFO pInfo, void *pvArg)
if (!*usages)
{
cUsages = 0;
*usages = WINTRUST_Alloc(2 * sizeof(PCCRYPT_OID_INFO));
*usages = malloc(2 * sizeof(PCCRYPT_OID_INFO));
}
else
{
......@@ -863,8 +844,7 @@ static BOOL WINAPI WINTRUST_enumUsages(PCCRYPT_OID_INFO pInfo, void *pvArg)
*/
for (cUsages = 0, ptr = *usages; *ptr; ptr++, cUsages++)
;
*usages = WINTRUST_ReAlloc(*usages,
(cUsages + 2) * sizeof(PCCRYPT_OID_INFO));
*usages = realloc(*usages, (cUsages + 2) * sizeof(PCCRYPT_OID_INFO));
}
if (*usages)
{
......@@ -916,7 +896,7 @@ BOOL WINAPI WTHelperGetKnownUsages(DWORD action, PCCRYPT_OID_INFO **usages)
}
else if (action == 2)
{
WINTRUST_Free(*usages);
free(*usages);
*usages = NULL;
ret = TRUE;
}
......@@ -1003,14 +983,7 @@ BOOL WINAPI WINTRUST_AddStore(CRYPT_PROVIDER_DATA *data, HCERTSTORE store)
TRACE("(%p, %p)\n", data, store);
if (data->chStores)
data->pahStores = WINTRUST_ReAlloc(data->pahStores,
(data->chStores + 1) * sizeof(HCERTSTORE));
else
{
data->pahStores = WINTRUST_Alloc(sizeof(HCERTSTORE));
data->chStores = 0;
}
data->pahStores = realloc(data->pahStores, (data->chStores + 1) * sizeof(HCERTSTORE));
if (data->pahStores)
{
data->pahStores[data->chStores++] = CertDuplicateStore(store);
......@@ -1039,14 +1012,8 @@ BOOL WINAPI WINTRUST_AddSgnr(CRYPT_PROVIDER_DATA *data,
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (data->csSigners)
data->pasSigners = WINTRUST_ReAlloc(data->pasSigners,
data->pasSigners = realloc(data->pasSigners,
(data->csSigners + 1) * sizeof(CRYPT_PROVIDER_SGNR));
else
{
data->pasSigners = WINTRUST_Alloc(sizeof(CRYPT_PROVIDER_SGNR));
data->csSigners = 0;
}
if (data->pasSigners)
{
if (idxSigner < data->csSigners)
......@@ -1088,17 +1055,10 @@ BOOL WINAPI WINTRUST_AddCert(CRYPT_PROVIDER_DATA *data, DWORD idxSigner,
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (data->pasSigners[idxSigner].csCertChain)
data->pasSigners[idxSigner].pasCertChain =
WINTRUST_ReAlloc(data->pasSigners[idxSigner].pasCertChain,
realloc(data->pasSigners[idxSigner].pasCertChain,
(data->pasSigners[idxSigner].csCertChain + 1) *
sizeof(CRYPT_PROVIDER_CERT));
else
{
data->pasSigners[idxSigner].pasCertChain =
WINTRUST_Alloc(sizeof(CRYPT_PROVIDER_CERT));
data->pasSigners[idxSigner].csCertChain = 0;
}
if (data->pasSigners[idxSigner].pasCertChain)
{
CRYPT_PROVIDER_CERT *cert = &data->pasSigners[idxSigner].pasCertChain[
......@@ -1127,14 +1087,8 @@ BOOL WINAPI WINTRUST_AddPrivData(CRYPT_PROVIDER_DATA *data,
WARN("invalid struct size\n");
return FALSE;
}
if (data->csProvPrivData)
data->pasProvPrivData = WINTRUST_ReAlloc(data->pasProvPrivData,
data->pasProvPrivData = realloc(data->pasProvPrivData,
(data->csProvPrivData + 1) * sizeof(CRYPT_PROVIDER_SGNR));
else
{
data->pasProvPrivData = WINTRUST_Alloc(sizeof(CRYPT_PROVIDER_SGNR));
data->csProvPrivData = 0;
}
if (data->pasProvPrivData)
{
DWORD i;
......
......@@ -18,9 +18,6 @@
#ifndef __WINTRUST_PRIV_H__
#define __WINTRUST_PRIV_H__
void WINAPI WINTRUST_Free(void *p) DECLSPEC_HIDDEN;
void * WINAPI WINTRUST_Alloc(DWORD cb)
__WINE_ALLOC_SIZE(1) __WINE_DEALLOC(WINTRUST_Free) __WINE_MALLOC DECLSPEC_HIDDEN;
BOOL WINAPI WINTRUST_AddStore(CRYPT_PROVIDER_DATA *data, HCERTSTORE store) DECLSPEC_HIDDEN;
BOOL WINAPI WINTRUST_AddSgnr(CRYPT_PROVIDER_DATA *data,
BOOL fCounterSigner, DWORD idxSigner, CRYPT_PROVIDER_SGNR *sgnr) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment