crypt32: Use CRYPT_EncodeEnsureSpace to allocate memory when necessary.
This commit is contained in:
parent
97f2c658fd
commit
74addd636e
|
@ -1176,42 +1176,34 @@ static BOOL WINAPI CRYPT_DEREncodeSet(DWORD dwCertEncodingType,
|
||||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
|
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
|
||||||
{
|
{
|
||||||
CRYPT_SET_OF *set = (CRYPT_SET_OF *)pvStructInfo;
|
const CRYPT_SET_OF *set = (const CRYPT_SET_OF *)pvStructInfo;
|
||||||
DWORD bytesNeeded = 0, lenBytes, i;
|
DWORD bytesNeeded = 0, lenBytes, i;
|
||||||
BOOL ret = FALSE;
|
BOOL ret;
|
||||||
|
|
||||||
for (i = 0; i < set->cValue; i++)
|
for (i = 0; i < set->cValue; i++)
|
||||||
bytesNeeded += set->rgValue[i].cbData;
|
bytesNeeded += set->rgValue[i].cbData;
|
||||||
CRYPT_EncodeLen(bytesNeeded, NULL, &lenBytes);
|
CRYPT_EncodeLen(bytesNeeded, NULL, &lenBytes);
|
||||||
bytesNeeded += 1 + lenBytes;
|
bytesNeeded += 1 + lenBytes;
|
||||||
if (pbEncoded)
|
if (!pbEncoded)
|
||||||
{
|
|
||||||
if (*pcbEncoded < bytesNeeded)
|
|
||||||
{
|
{
|
||||||
*pcbEncoded = bytesNeeded;
|
*pcbEncoded = bytesNeeded;
|
||||||
SetLastError(ERROR_MORE_DATA);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
*pcbEncoded = bytesNeeded;
|
}
|
||||||
|
else if ((ret = CRYPT_EncodeEnsureSpace(dwFlags, pEncodePara,
|
||||||
|
pbEncoded, pcbEncoded, bytesNeeded)))
|
||||||
|
{
|
||||||
|
if (dwFlags & CRYPT_ENCODE_ALLOC_FLAG)
|
||||||
|
pbEncoded = *(BYTE **)pbEncoded;
|
||||||
qsort(set->rgValue, set->cValue, sizeof(CRYPT_DER_BLOB), BLOBComp);
|
qsort(set->rgValue, set->cValue, sizeof(CRYPT_DER_BLOB), BLOBComp);
|
||||||
*pbEncoded++ = ASN_CONSTRUCTOR | ASN_SETOF;
|
*pbEncoded++ = ASN_CONSTRUCTOR | ASN_SETOF;
|
||||||
CRYPT_EncodeLen(bytesNeeded - lenBytes - 1, pbEncoded, &lenBytes);
|
CRYPT_EncodeLen(bytesNeeded - lenBytes - 1, pbEncoded, &lenBytes);
|
||||||
pbEncoded += lenBytes;
|
pbEncoded += lenBytes;
|
||||||
for (i = 0; ret && i < set->cValue; i++)
|
for (i = 0; ret && i < set->cValue; i++)
|
||||||
{
|
{
|
||||||
memcpy(pbEncoded, set->rgValue[i].pbData,
|
memcpy(pbEncoded, set->rgValue[i].pbData, set->rgValue[i].cbData);
|
||||||
set->rgValue[i].cbData);
|
|
||||||
pbEncoded += set->rgValue[i].cbData;
|
pbEncoded += set->rgValue[i].cbData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*pcbEncoded = bytesNeeded;
|
|
||||||
ret = TRUE;
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue