Commit c48c5c85 authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

crypt32: Fix the aligning up to a DWORD_PTR boundary.

parent c46a88a3
...@@ -376,4 +376,13 @@ void ContextList_Empty(struct ContextList *list); ...@@ -376,4 +376,13 @@ void ContextList_Empty(struct ContextList *list);
void ContextList_Free(struct ContextList *list); void ContextList_Free(struct ContextList *list);
/**
* Utilities.
*/
/* Align up to a DWORD_PTR boundary
*/
#define ALIGN_DWORD_PTR(x) (((x) + sizeof(DWORD_PTR) - 1) & ~(sizeof(DWORD_PTR) - 1))
#define POINTER_ALIGN_DWORD_PTR(p) ((LPVOID)ALIGN_DWORD_PTR((DWORD_PTR)(p)))
#endif #endif
...@@ -362,9 +362,7 @@ static BOOL CRYPT_AsnDecodeSequenceItems(struct AsnDecodeSequenceItem items[], ...@@ -362,9 +362,7 @@ static BOOL CRYPT_AsnDecodeSequenceItems(struct AsnDecodeSequenceItem items[],
if (ret) if (ret)
{ {
/* Account for alignment padding */ /* Account for alignment padding */
if (items[i].size % sizeof(DWORD_PTR)) items[i].size = ALIGN_DWORD_PTR(items[i].size);
items[i].size += sizeof(DWORD_PTR) -
items[i].size % sizeof(DWORD_PTR);
TRACE("item %d size: %d\n", i, items[i].size); TRACE("item %d size: %d\n", i, items[i].size);
if (nextData && items[i].hasPointer && if (nextData && items[i].hasPointer &&
items[i].size > items[i].minSize) items[i].size > items[i].minSize)
......
...@@ -1970,8 +1970,7 @@ static inline void CRYPT_CopyAttributes(CRYPT_ATTRIBUTES *out, ...@@ -1970,8 +1970,7 @@ static inline void CRYPT_CopyAttributes(CRYPT_ATTRIBUTES *out,
{ {
DWORD i; DWORD i;
if ((*nextData - (LPBYTE)0) % sizeof(DWORD_PTR)) *nextData = POINTER_ALIGN_DWORD_PTR(*nextData);
*nextData += (*nextData - (LPBYTE)0) % sizeof(DWORD_PTR);
out->rgAttr = (CRYPT_ATTRIBUTE *)*nextData; out->rgAttr = (CRYPT_ATTRIBUTE *)*nextData;
*nextData += in->cAttr * sizeof(CRYPT_ATTRIBUTE); *nextData += in->cAttr * sizeof(CRYPT_ATTRIBUTE);
for (i = 0; i < in->cAttr; i++) for (i = 0; i < in->cAttr; i++)
...@@ -1987,8 +1986,7 @@ static inline void CRYPT_CopyAttributes(CRYPT_ATTRIBUTES *out, ...@@ -1987,8 +1986,7 @@ static inline void CRYPT_CopyAttributes(CRYPT_ATTRIBUTES *out,
DWORD j; DWORD j;
out->rgAttr[i].cValue = in->rgAttr[i].cValue; out->rgAttr[i].cValue = in->rgAttr[i].cValue;
if ((*nextData - (LPBYTE)0) % sizeof(DWORD_PTR)) *nextData = POINTER_ALIGN_DWORD_PTR(*nextData);
*nextData += (*nextData - (LPBYTE)0) % sizeof(DWORD_PTR);
out->rgAttr[i].rgValue = (PCRYPT_DATA_BLOB)*nextData; out->rgAttr[i].rgValue = (PCRYPT_DATA_BLOB)*nextData;
*nextData += in->rgAttr[i].cValue * sizeof(CRYPT_DATA_BLOB); *nextData += in->rgAttr[i].cValue * sizeof(CRYPT_DATA_BLOB);
for (j = 0; j < in->rgAttr[i].cValue; j++) for (j = 0; j < in->rgAttr[i].cValue; j++)
...@@ -2008,15 +2006,13 @@ static DWORD CRYPT_SizeOfAttributes(const CRYPT_ATTRIBUTES *attr) ...@@ -2008,15 +2006,13 @@ static DWORD CRYPT_SizeOfAttributes(const CRYPT_ATTRIBUTES *attr)
if (attr->rgAttr[i].pszObjId) if (attr->rgAttr[i].pszObjId)
size += strlen(attr->rgAttr[i].pszObjId) + 1; size += strlen(attr->rgAttr[i].pszObjId) + 1;
/* align pointer */ /* align pointer */
if (size % sizeof(DWORD_PTR)) size = ALIGN_DWORD_PTR(size);
size += size % sizeof(DWORD_PTR);
size += attr->rgAttr[i].cValue * sizeof(CRYPT_DATA_BLOB); size += attr->rgAttr[i].cValue * sizeof(CRYPT_DATA_BLOB);
for (j = 0; j < attr->rgAttr[i].cValue; j++) for (j = 0; j < attr->rgAttr[i].cValue; j++)
size += attr->rgAttr[i].rgValue[j].cbData; size += attr->rgAttr[i].rgValue[j].cbData;
} }
/* align pointer again to be conservative */ /* align pointer again to be conservative */
if (size % sizeof(DWORD_PTR)) size = ALIGN_DWORD_PTR(size);
size += size % sizeof(DWORD_PTR);
return size; return size;
} }
...@@ -2094,8 +2090,7 @@ static BOOL CRYPT_CopySignerInfo(void *pvData, DWORD *pcbData, ...@@ -2094,8 +2090,7 @@ static BOOL CRYPT_CopySignerInfo(void *pvData, DWORD *pcbData,
size += in->HashEncryptionAlgorithm.Parameters.cbData; size += in->HashEncryptionAlgorithm.Parameters.cbData;
size += in->EncryptedHash.cbData; size += in->EncryptedHash.cbData;
/* align pointer */ /* align pointer */
if (size % sizeof(DWORD_PTR)) size = ALIGN_DWORD_PTR(size);
size += size % sizeof(DWORD_PTR);
size += CRYPT_SizeOfAttributes(&in->AuthAttrs); size += CRYPT_SizeOfAttributes(&in->AuthAttrs);
size += CRYPT_SizeOfAttributes(&in->UnauthAttrs); size += CRYPT_SizeOfAttributes(&in->UnauthAttrs);
if (!pvData) if (!pvData)
...@@ -2133,9 +2128,7 @@ static BOOL CRYPT_CopySignerInfo(void *pvData, DWORD *pcbData, ...@@ -2133,9 +2128,7 @@ static BOOL CRYPT_CopySignerInfo(void *pvData, DWORD *pcbData,
CRYPT_CopyAlgorithmId(&out->HashEncryptionAlgorithm, CRYPT_CopyAlgorithmId(&out->HashEncryptionAlgorithm,
&in->HashEncryptionAlgorithm, &nextData); &in->HashEncryptionAlgorithm, &nextData);
CRYPT_CopyBlob(&out->EncryptedHash, &in->EncryptedHash, &nextData); CRYPT_CopyBlob(&out->EncryptedHash, &in->EncryptedHash, &nextData);
/* align pointer */ nextData = POINTER_ALIGN_DWORD_PTR(nextData);
if ((nextData - (LPBYTE)0) % sizeof(DWORD_PTR))
nextData += (nextData - (LPBYTE)0) % sizeof(DWORD_PTR);
CRYPT_CopyAttributes(&out->AuthAttrs, &in->AuthAttrs, &nextData); CRYPT_CopyAttributes(&out->AuthAttrs, &in->AuthAttrs, &nextData);
CRYPT_CopyAttributes(&out->UnauthAttrs, &in->UnauthAttrs, &nextData); CRYPT_CopyAttributes(&out->UnauthAttrs, &in->UnauthAttrs, &nextData);
} }
...@@ -2167,8 +2160,7 @@ static BOOL CRYPT_CopyCMSSignerInfo(void *pvData, DWORD *pcbData, ...@@ -2167,8 +2160,7 @@ static BOOL CRYPT_CopyCMSSignerInfo(void *pvData, DWORD *pcbData,
size += in->HashEncryptionAlgorithm.Parameters.cbData; size += in->HashEncryptionAlgorithm.Parameters.cbData;
size += in->EncryptedHash.cbData; size += in->EncryptedHash.cbData;
/* align pointer */ /* align pointer */
if (size % sizeof(DWORD_PTR)) size = ALIGN_DWORD_PTR(size);
size += size % sizeof(DWORD_PTR);
size += CRYPT_SizeOfAttributes(&in->AuthAttrs); size += CRYPT_SizeOfAttributes(&in->AuthAttrs);
size += CRYPT_SizeOfAttributes(&in->UnauthAttrs); size += CRYPT_SizeOfAttributes(&in->UnauthAttrs);
if (!pvData) if (!pvData)
...@@ -2203,9 +2195,7 @@ static BOOL CRYPT_CopyCMSSignerInfo(void *pvData, DWORD *pcbData, ...@@ -2203,9 +2195,7 @@ static BOOL CRYPT_CopyCMSSignerInfo(void *pvData, DWORD *pcbData,
CRYPT_CopyAlgorithmId(&out->HashEncryptionAlgorithm, CRYPT_CopyAlgorithmId(&out->HashEncryptionAlgorithm,
&in->HashEncryptionAlgorithm, &nextData); &in->HashEncryptionAlgorithm, &nextData);
CRYPT_CopyBlob(&out->EncryptedHash, &in->EncryptedHash, &nextData); CRYPT_CopyBlob(&out->EncryptedHash, &in->EncryptedHash, &nextData);
/* align pointer */ nextData = POINTER_ALIGN_DWORD_PTR(nextData);
if ((nextData - (LPBYTE)0) % sizeof(DWORD_PTR))
nextData += (nextData - (LPBYTE)0) % sizeof(DWORD_PTR);
CRYPT_CopyAttributes(&out->AuthAttrs, &in->AuthAttrs, &nextData); CRYPT_CopyAttributes(&out->AuthAttrs, &in->AuthAttrs, &nextData);
CRYPT_CopyAttributes(&out->UnauthAttrs, &in->UnauthAttrs, &nextData); CRYPT_CopyAttributes(&out->UnauthAttrs, &in->UnauthAttrs, &nextData);
ret = TRUE; ret = TRUE;
......
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