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

wintrust: Use CRT allocation functions.

parent 537bcadb
......@@ -70,7 +70,7 @@ static HCATINFO create_catinfo(const WCHAR *filename)
{
struct catinfo *ci;
if (!(ci = HeapAlloc(GetProcessHeap(), 0, sizeof(*ci))))
if (!(ci = malloc(sizeof(*ci))))
{
SetLastError(ERROR_OUTOFMEMORY);
return INVALID_HANDLE_VALUE;
......@@ -118,7 +118,7 @@ BOOL WINAPI CryptCATAdminAcquireContext(HCATADMIN *catAdmin,
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (!(ca = HeapAlloc(GetProcessHeap(), 0, sizeof(*ca))))
if (!(ca = malloc(sizeof(*ca))))
{
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
......@@ -185,7 +185,7 @@ HCATINFO WINAPI CryptCATAdminAddCatalog(HCATADMIN catAdmin, PWSTR catalogFile,
}
len = lstrlenW(ca->path) + lstrlenW(selectBaseName) + 2;
if (!(target = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
if (!(target = malloc(len * sizeof(WCHAR))))
{
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
......@@ -196,21 +196,21 @@ HCATINFO WINAPI CryptCATAdminAddCatalog(HCATADMIN catAdmin, PWSTR catalogFile,
if (!CopyFileW(catalogFile, target, FALSE))
{
HeapFree(GetProcessHeap(), 0, target);
free(target);
return NULL;
}
SetFileAttributesW(target, FILE_ATTRIBUTE_SYSTEM);
if (!(ci = HeapAlloc(GetProcessHeap(), 0, sizeof(*ci))))
if (!(ci = malloc(sizeof(*ci))))
{
HeapFree(GetProcessHeap(), 0, target);
free(target);
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
}
ci->magic = CATINFO_MAGIC;
lstrcpyW(ci->file, target);
HeapFree(GetProcessHeap(), 0, target);
free(target);
return ci;
}
......@@ -244,7 +244,7 @@ BOOL WINAPI CryptCATAdminCalcHashFromFileHandle(HANDLE hFile, DWORD* pcbHash,
DWORD bytes_read;
BYTE *buffer;
if (!(buffer = HeapAlloc(GetProcessHeap(), 0, 4096)))
if (!(buffer = malloc(4096)))
{
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
......@@ -252,13 +252,13 @@ BOOL WINAPI CryptCATAdminCalcHashFromFileHandle(HANDLE hFile, DWORD* pcbHash,
ret = CryptAcquireContextW(&prov, NULL, MS_DEF_PROV_W, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
if (!ret)
{
HeapFree(GetProcessHeap(), 0, buffer);
free(buffer);
return FALSE;
}
ret = CryptCreateHash(prov, CALG_SHA1, 0, 0, &hash);
if (!ret)
{
HeapFree(GetProcessHeap(), 0, buffer);
free(buffer);
CryptReleaseContext(prov, 0);
return FALSE;
}
......@@ -268,7 +268,7 @@ BOOL WINAPI CryptCATAdminCalcHashFromFileHandle(HANDLE hFile, DWORD* pcbHash,
}
if (ret) ret = CryptGetHashParam(hash, HP_HASHVAL, pbHash, pcbHash, 0);
HeapFree(GetProcessHeap(), 0, buffer);
free(buffer);
CryptDestroyHash(hash);
CryptReleaseContext(prov, 0);
}
......@@ -309,7 +309,7 @@ HCATINFO WINAPI CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin, BYTE* pbHa
WCHAR *path;
size = lstrlenW(ca->path) * sizeof(WCHAR) + sizeof(globW);
if (!(path = HeapAlloc(GetProcessHeap(), 0, size)))
if (!(path = malloc(size)))
{
CryptReleaseContext(prov, 0);
SetLastError(ERROR_OUTOFMEMORY);
......@@ -321,7 +321,7 @@ HCATINFO WINAPI CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin, BYTE* pbHa
FindClose(ca->find);
ca->find = FindFirstFileW(path, &data);
HeapFree(GetProcessHeap(), 0, path);
free(path);
if (ca->find == INVALID_HANDLE_VALUE)
{
CryptReleaseContext(prov, 0);
......@@ -343,7 +343,7 @@ HCATINFO WINAPI CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin, BYTE* pbHa
HANDLE hcat;
size = (lstrlenW(ca->path) + lstrlenW(data.cFileName) + 2) * sizeof(WCHAR);
if (!(filename = HeapAlloc(GetProcessHeap(), 0, size)))
if (!(filename = malloc(size)))
{
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
......@@ -377,12 +377,12 @@ HCATINFO WINAPI CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin, BYTE* pbHa
ca->find = INVALID_HANDLE_VALUE;
}
ci = create_catinfo(filename);
HeapFree(GetProcessHeap(), 0, filename);
free(filename);
return ci;
}
}
CryptCATClose(hcat);
HeapFree(GetProcessHeap(), 0, filename);
free(filename);
if (!FindNextFileW(ca->find, &data))
{
......@@ -425,7 +425,8 @@ BOOL WINAPI CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin,
return FALSE;
}
ci->magic = 0;
return HeapFree(GetProcessHeap(), 0, ci);
free(ci);
return TRUE;
}
/***********************************************************************
......@@ -455,7 +456,8 @@ BOOL WINAPI CryptCATAdminReleaseContext(HCATADMIN hCatAdmin, DWORD dwFlags )
}
if (ca->find != INVALID_HANDLE_VALUE) FindClose(ca->find);
ca->magic = 0;
return HeapFree(GetProcessHeap(), 0, ca);
free(ca);
return TRUE;
}
/***********************************************************************
......@@ -495,7 +497,7 @@ BOOL WINAPI CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin, LPCWSTR pwszCatalogF
DWORD len;
len = lstrlenW(ca->path) + lstrlenW(pwszCatalogFile) + 2;
if (!(target = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
if (!(target = malloc(len * sizeof(WCHAR))))
{
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
......@@ -506,7 +508,7 @@ BOOL WINAPI CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin, LPCWSTR pwszCatalogF
DeleteFileW(target);
HeapFree(GetProcessHeap(), 0, target);
free(target);
}
return TRUE;
......@@ -549,12 +551,12 @@ BOOL WINAPI CryptCATClose(HANDLE hCatalog)
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
HeapFree(GetProcessHeap(), 0, cc->attr);
HeapFree(GetProcessHeap(), 0, cc->inner);
free(cc->attr);
free(cc->inner);
CryptMsgClose(cc->msg);
cc->magic = 0;
HeapFree(GetProcessHeap(), 0, cc);
free(cc);
return TRUE;
}
......@@ -666,7 +668,7 @@ CRYPTCATMEMBER * WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER
/* dumping the contents makes me think that dwReserved is the iteration number */
if (!member)
{
if (!(member = HeapAlloc(GetProcessHeap(), 0, sizeof(*member))))
if (!(member = malloc(sizeof(*member))))
{
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
......@@ -693,7 +695,7 @@ CRYPTCATMEMBER * WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER
member->sEncodedIndirectData.cbData = member->sEncodedMemberInfo.cbData = 0;
member->sEncodedIndirectData.pbData = member->sEncodedMemberInfo.pbData = NULL;
HeapFree(GetProcessHeap(), 0, member->pIndirectData);
free(member->pIndirectData);
member->pIndirectData = NULL;
for (i = 0; i < entry->cAttribute; i++)
......@@ -715,7 +717,7 @@ CRYPTCATMEMBER * WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER
CryptDecodeObject(cc->encoding, CAT_MEMBERINFO_OBJID, attr->rgValue->pbData, attr->rgValue->cbData, 0, NULL, &size);
if (!(mi = HeapAlloc(GetProcessHeap(), 0, size)))
if (!(mi = malloc(size)))
{
SetLastError(ERROR_OUTOFMEMORY);
goto error;
......@@ -729,11 +731,11 @@ CRYPTCATMEMBER * WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER
RtlInitUnicodeString(&guid, mi->pwszSubjGuid);
if (RtlGUIDFromString(&guid, &member->gSubjectType))
{
HeapFree(GetProcessHeap(), 0, mi);
free(mi);
goto error;
}
}
HeapFree(GetProcessHeap(), 0, mi);
free(mi);
if (!ret) goto error;
}
else if (!strcmp(attr->pszObjId, SPC_INDIRECT_DATA_OBJID))
......@@ -745,7 +747,7 @@ CRYPTCATMEMBER * WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER
CryptDecodeObject(cc->encoding, SPC_INDIRECT_DATA_OBJID, attr->rgValue->pbData, attr->rgValue->cbData, 0, NULL, &size);
if (!(member->pIndirectData = HeapAlloc(GetProcessHeap(), 0, size)))
if (!(member->pIndirectData = malloc(size)))
{
SetLastError(ERROR_OUTOFMEMORY);
goto error;
......@@ -764,10 +766,7 @@ CRYPTCATMEMBER * WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER
goto error;
}
size = (2 * member->pIndirectData->Digest.cbData + 1) * sizeof(WCHAR);
if (member->pwszReferenceTag)
member->pwszReferenceTag = HeapReAlloc(GetProcessHeap(), 0, member->pwszReferenceTag, size);
else
member->pwszReferenceTag = HeapAlloc(GetProcessHeap(), 0, size);
member->pwszReferenceTag = realloc(member->pwszReferenceTag, size);
if (!member->pwszReferenceTag)
{
......@@ -788,9 +787,9 @@ CRYPTCATMEMBER * WINAPI CryptCATEnumerateMember(HANDLE hCatalog, CRYPTCATMEMBER
return member;
error:
HeapFree(GetProcessHeap(), 0, member->pIndirectData);
HeapFree(GetProcessHeap(), 0, member->pwszReferenceTag);
HeapFree(GetProcessHeap(), 0, member);
free(member->pIndirectData);
free(member->pwszReferenceTag);
free(member);
return NULL;
}
......@@ -802,21 +801,21 @@ static CTL_INFO *decode_inner_content(HANDLE hmsg, DWORD encoding, DWORD *len)
CTL_INFO *inner = NULL;
if (!CryptMsgGetParam(hmsg, CMSG_INNER_CONTENT_TYPE_PARAM, 0, NULL, &size)) return NULL;
if (!(oid = HeapAlloc(GetProcessHeap(), 0, size)))
if (!(oid = malloc(size)))
{
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
}
if (!CryptMsgGetParam(hmsg, CMSG_INNER_CONTENT_TYPE_PARAM, 0, oid, &size)) goto out;
if (!CryptMsgGetParam(hmsg, CMSG_CONTENT_PARAM, 0, NULL, &size)) goto out;
if (!(buffer = HeapAlloc(GetProcessHeap(), 0, size)))
if (!(buffer = malloc(size)))
{
SetLastError(ERROR_OUTOFMEMORY);
goto out;
}
if (!CryptMsgGetParam(hmsg, CMSG_CONTENT_PARAM, 0, buffer, &size)) goto out;
if (!CryptDecodeObject(encoding, oid, buffer, size, 0, NULL, &size)) goto out;
if (!(inner = HeapAlloc(GetProcessHeap(), 0, size)))
if (!(inner = malloc(size)))
{
SetLastError(ERROR_OUTOFMEMORY);
goto out;
......@@ -825,8 +824,8 @@ static CTL_INFO *decode_inner_content(HANDLE hmsg, DWORD encoding, DWORD *len)
*len = size;
out:
HeapFree(GetProcessHeap(), 0, oid);
HeapFree(GetProcessHeap(), 0, buffer);
free(oid);
free(buffer);
return inner;
}
......@@ -931,7 +930,7 @@ HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv,
if (file == INVALID_HANDLE_VALUE) return INVALID_HANDLE_VALUE;
size = GetFileSize(file, NULL);
if (!(buffer = HeapAlloc(GetProcessHeap(), 0, size)))
if (!(buffer = malloc(size)))
{
CloseHandle(file);
SetLastError(ERROR_OUTOFMEMORY);
......@@ -940,23 +939,23 @@ HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv,
if (!(hmsg = CryptMsgOpenToDecode(dwEncodingType, 0, 0, hProv, NULL, NULL)))
{
CloseHandle(file);
HeapFree(GetProcessHeap(), 0, buffer);
free(buffer);
return INVALID_HANDLE_VALUE;
}
if (!size) valid = FALSE;
else if (!ReadFile(file, buffer, size, &size, NULL))
{
CloseHandle(file);
HeapFree(GetProcessHeap(), 0, buffer);
free(buffer);
CryptMsgClose(hmsg);
return INVALID_HANDLE_VALUE;
}
else valid = CryptMsgUpdate(hmsg, buffer, size, TRUE);
HeapFree(GetProcessHeap(), 0, buffer);
free(buffer);
CloseHandle(file);
size = sizeof(DWORD);
if (!(cc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*cc))))
if (!(cc = calloc(1, sizeof(*cc))))
{
CryptMsgClose(hmsg);
SetLastError(ERROR_OUTOFMEMORY);
......@@ -981,15 +980,15 @@ HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv,
if (!CryptMsgGetParam(hmsg, CMSG_ATTR_CERT_PARAM, i, NULL, &size))
{
CryptMsgClose(hmsg);
HeapFree(GetProcessHeap(), 0, cc);
free(cc);
return INVALID_HANDLE_VALUE;
}
sum += size;
}
if (!(cc->attr = HeapAlloc(GetProcessHeap(), 0, sizeof(*cc->attr) * cc->attr_count + sum)))
if (!(cc->attr = malloc(sizeof(*cc->attr) * cc->attr_count + sum)))
{
CryptMsgClose(hmsg);
HeapFree(GetProcessHeap(), 0, cc);
free(cc);
SetLastError(ERROR_OUTOFMEMORY);
return INVALID_HANDLE_VALUE;
}
......@@ -999,15 +998,15 @@ HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv,
if (!CryptMsgGetParam(hmsg, CMSG_ATTR_CERT_PARAM, i, NULL, &size))
{
CryptMsgClose(hmsg);
HeapFree(GetProcessHeap(), 0, cc->attr);
HeapFree(GetProcessHeap(), 0, cc);
free(cc->attr);
free(cc);
return INVALID_HANDLE_VALUE;
}
if (!CryptMsgGetParam(hmsg, CMSG_ATTR_CERT_PARAM, i, p, &size))
{
CryptMsgClose(hmsg);
HeapFree(GetProcessHeap(), 0, cc->attr);
HeapFree(GetProcessHeap(), 0, cc);
free(cc->attr);
free(cc);
return INVALID_HANDLE_VALUE;
}
p += size;
......@@ -1016,16 +1015,16 @@ HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv,
if (!cc->inner || !CryptSIPRetrieveSubjectGuid(filename, NULL, &cc->subject))
{
CryptMsgClose(hmsg);
HeapFree(GetProcessHeap(), 0, cc->attr);
HeapFree(GetProcessHeap(), 0, cc->inner);
HeapFree(GetProcessHeap(), 0, cc);
free(cc->attr);
free(cc->inner);
free(cc);
return INVALID_HANDLE_VALUE;
}
cc->magic = CRYPTCAT_MAGIC;
SetLastError(ERROR_SUCCESS);
return cc;
}
HeapFree(GetProcessHeap(), 0, cc);
free(cc);
return INVALID_HANDLE_VALUE;
}
......@@ -1136,7 +1135,7 @@ static BOOL WINTRUST_GetSignedMsgFromPEFile(SIP_SUBJECTINFO *pSubjectInfo,
ret = ImageGetCertificateData(file, dwIndex, NULL, &len);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
goto error;
pCert = HeapAlloc(GetProcessHeap(), 0, len);
pCert = malloc(len);
if (!pCert)
{
ret = FALSE;
......@@ -1175,7 +1174,7 @@ static BOOL WINTRUST_GetSignedMsgFromPEFile(SIP_SUBJECTINFO *pSubjectInfo,
error:
if(pSubjectInfo->hFile != file)
CloseHandle(file);
HeapFree(GetProcessHeap(), 0, pCert);
free(pCert);
return ret;
}
......@@ -1199,7 +1198,7 @@ static BOOL WINTRUST_PutSignedMsgToPEFile(SIP_SUBJECTINFO* pSubjectInfo, DWORD p
/* int aligned WIN_CERTIFICATE structure with cbSignedDataMsg+1 bytes of data */
size = FIELD_OFFSET(WIN_CERTIFICATE, bCertificate[cbSignedDataMsg+4]) & (~3);
cert = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
cert = calloc(1, size);
if(!cert)
return FALSE;
......@@ -1209,7 +1208,7 @@ static BOOL WINTRUST_PutSignedMsgToPEFile(SIP_SUBJECTINFO* pSubjectInfo, DWORD p
memcpy(cert->bCertificate, pbSignedDataMsg, cbSignedDataMsg);
ret = ImageAddCertificate(file, cert, pdwIndex);
HeapFree(GetProcessHeap(), 0, cert);
free(cert);
if(file != pSubjectInfo->hFile)
CloseHandle(file);
return ret;
......
......@@ -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