Juan Lang : crypt32: Introduce a space checking helper for functions that don' t allocate memory and use it where appropriate.
Alexandre Julliard
julliard at winehq.org
Tue Sep 18 05:31:25 CDT 2007
Module: wine
Branch: master
Commit: 8c5bd5f5ca6c2543d7a20a2761e0f5b78bff4f1f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=8c5bd5f5ca6c2543d7a20a2761e0f5b78bff4f1f
Author: Juan Lang <juan.lang at gmail.com>
Date: Mon Sep 17 17:04:40 2007 -0700
crypt32: Introduce a space checking helper for functions that don't allocate memory and use it where appropriate.
---
dlls/crypt32/decode.c | 39 +++++++++++++++++++++++++++------------
1 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/dlls/crypt32/decode.c b/dlls/crypt32/decode.c
index 9cc4c0c..02bb308 100644
--- a/dlls/crypt32/decode.c
+++ b/dlls/crypt32/decode.c
@@ -250,6 +250,27 @@ static BOOL CRYPT_DecodeEnsureSpace(DWORD dwFlags,
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:
* The expected tag of the item. If tag is 0, decodeFunc is called
* regardless of the tag value seen.
@@ -705,8 +726,7 @@ static BOOL WINAPI CRYPT_AsnDecodeDerBlob(DWORD dwCertEncodingType,
if (!pvStructInfo)
*pcbStructInfo = bytesNeeded;
- else if ((ret = CRYPT_DecodeEnsureSpace(dwFlags, pDecodePara,
- pvStructInfo, pcbStructInfo, bytesNeeded)))
+ else if ((ret = CRYPT_DecodeCheckSpace(pcbStructInfo, bytesNeeded)))
{
CRYPT_DER_BLOB *blob;
@@ -3055,8 +3075,7 @@ static BOOL CRYPT_AsnDecodeIntInternal(const BYTE *pbEncoded, DWORD cbEncoded,
{
if (!pvStructInfo)
*pcbStructInfo = sizeof(int);
- else if ((ret = CRYPT_DecodeEnsureSpace(dwFlags, NULL,
- pvStructInfo, pcbStructInfo, sizeof(int))))
+ else if ((ret = CRYPT_DecodeCheckSpace(pcbStructInfo, sizeof(int))))
{
int val, i;
@@ -3515,8 +3534,8 @@ static BOOL CRYPT_AsnDecodeUtcTimeInternal(const BYTE *pbEncoded,
{
if (!pvStructInfo)
*pcbStructInfo = sizeof(FILETIME);
- else if ((ret = CRYPT_DecodeEnsureSpace(dwFlags, NULL,
- pvStructInfo, pcbStructInfo, sizeof(FILETIME))))
+ else if ((ret = CRYPT_DecodeCheckSpace(pcbStructInfo,
+ sizeof(FILETIME))))
ret = SystemTimeToFileTime(&sysTime,
(FILETIME *)pvStructInfo);
}
@@ -3621,14 +3640,10 @@ static BOOL CRYPT_AsnDecodeGeneralizedTime(const BYTE *pbEncoded,
{
if (!pvStructInfo)
*pcbStructInfo = sizeof(FILETIME);
- else if ((ret = CRYPT_DecodeEnsureSpace(dwFlags, NULL,
- pvStructInfo, pcbStructInfo, sizeof(FILETIME))))
- {
- if (dwFlags & CRYPT_DECODE_ALLOC_FLAG)
- pvStructInfo = *(BYTE **)pvStructInfo;
+ else if ((ret = CRYPT_DecodeCheckSpace(pcbStructInfo,
+ sizeof(FILETIME))))
ret = SystemTimeToFileTime(&sysTime,
(FILETIME *)pvStructInfo);
- }
}
}
}
More information about the wine-cvs
mailing list