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