Commit 8c5bd5f5 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

crypt32: Introduce a space checking helper for functions that don't allocate…

crypt32: Introduce a space checking helper for functions that don't allocate memory and use it where appropriate.
parent 9d0dccf1
...@@ -250,6 +250,27 @@ static BOOL CRYPT_DecodeEnsureSpace(DWORD dwFlags, ...@@ -250,6 +250,27 @@ static BOOL CRYPT_DecodeEnsureSpace(DWORD dwFlags,
return ret; return ret;
} }
/* Helper function to check *pcbStructInfo and set it to the required size.
* Assumes pvStructInfo is not NULL.
*/
static BOOL CRYPT_DecodeCheckSpace(DWORD *pcbStructInfo, DWORD bytesNeeded)
{
BOOL ret;
if (*pcbStructInfo < bytesNeeded)
{
*pcbStructInfo = bytesNeeded;
SetLastError(ERROR_MORE_DATA);
ret = FALSE;
}
else
{
*pcbStructInfo = bytesNeeded;
ret = TRUE;
}
return ret;
}
/* tag: /* tag:
* The expected tag of the item. If tag is 0, decodeFunc is called * The expected tag of the item. If tag is 0, decodeFunc is called
* regardless of the tag value seen. * regardless of the tag value seen.
...@@ -705,8 +726,7 @@ static BOOL WINAPI CRYPT_AsnDecodeDerBlob(DWORD dwCertEncodingType, ...@@ -705,8 +726,7 @@ static BOOL WINAPI CRYPT_AsnDecodeDerBlob(DWORD dwCertEncodingType,
if (!pvStructInfo) if (!pvStructInfo)
*pcbStructInfo = bytesNeeded; *pcbStructInfo = bytesNeeded;
else if ((ret = CRYPT_DecodeEnsureSpace(dwFlags, pDecodePara, else if ((ret = CRYPT_DecodeCheckSpace(pcbStructInfo, bytesNeeded)))
pvStructInfo, pcbStructInfo, bytesNeeded)))
{ {
CRYPT_DER_BLOB *blob; CRYPT_DER_BLOB *blob;
...@@ -3055,8 +3075,7 @@ static BOOL CRYPT_AsnDecodeIntInternal(const BYTE *pbEncoded, DWORD cbEncoded, ...@@ -3055,8 +3075,7 @@ static BOOL CRYPT_AsnDecodeIntInternal(const BYTE *pbEncoded, DWORD cbEncoded,
{ {
if (!pvStructInfo) if (!pvStructInfo)
*pcbStructInfo = sizeof(int); *pcbStructInfo = sizeof(int);
else if ((ret = CRYPT_DecodeEnsureSpace(dwFlags, NULL, else if ((ret = CRYPT_DecodeCheckSpace(pcbStructInfo, sizeof(int))))
pvStructInfo, pcbStructInfo, sizeof(int))))
{ {
int val, i; int val, i;
...@@ -3515,8 +3534,8 @@ static BOOL CRYPT_AsnDecodeUtcTimeInternal(const BYTE *pbEncoded, ...@@ -3515,8 +3534,8 @@ static BOOL CRYPT_AsnDecodeUtcTimeInternal(const BYTE *pbEncoded,
{ {
if (!pvStructInfo) if (!pvStructInfo)
*pcbStructInfo = sizeof(FILETIME); *pcbStructInfo = sizeof(FILETIME);
else if ((ret = CRYPT_DecodeEnsureSpace(dwFlags, NULL, else if ((ret = CRYPT_DecodeCheckSpace(pcbStructInfo,
pvStructInfo, pcbStructInfo, sizeof(FILETIME)))) sizeof(FILETIME))))
ret = SystemTimeToFileTime(&sysTime, ret = SystemTimeToFileTime(&sysTime,
(FILETIME *)pvStructInfo); (FILETIME *)pvStructInfo);
} }
...@@ -3621,18 +3640,14 @@ static BOOL CRYPT_AsnDecodeGeneralizedTime(const BYTE *pbEncoded, ...@@ -3621,18 +3640,14 @@ static BOOL CRYPT_AsnDecodeGeneralizedTime(const BYTE *pbEncoded,
{ {
if (!pvStructInfo) if (!pvStructInfo)
*pcbStructInfo = sizeof(FILETIME); *pcbStructInfo = sizeof(FILETIME);
else if ((ret = CRYPT_DecodeEnsureSpace(dwFlags, NULL, else if ((ret = CRYPT_DecodeCheckSpace(pcbStructInfo,
pvStructInfo, pcbStructInfo, sizeof(FILETIME)))) sizeof(FILETIME))))
{
if (dwFlags & CRYPT_DECODE_ALLOC_FLAG)
pvStructInfo = *(BYTE **)pvStructInfo;
ret = SystemTimeToFileTime(&sysTime, ret = SystemTimeToFileTime(&sysTime,
(FILETIME *)pvStructInfo); (FILETIME *)pvStructInfo);
} }
} }
} }
} }
}
else else
SetLastError(CRYPT_E_ASN1_BADTAG); SetLastError(CRYPT_E_ASN1_BADTAG);
return ret; return ret;
......
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