From c48c5c8577774d45a94b65a5910f7f5f0d5f5f63 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Fri, 7 Nov 2008 01:01:39 +0100 Subject: [PATCH] crypt32: Fix the aligning up to a DWORD_PTR boundary. --- dlls/crypt32/crypt32_private.h | 9 +++++++++ dlls/crypt32/decode.c | 4 +--- dlls/crypt32/msg.c | 26 ++++++++------------------ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h index 81dd49e9c9d..119e30edc05 100644 --- a/dlls/crypt32/crypt32_private.h +++ b/dlls/crypt32/crypt32_private.h @@ -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 diff --git a/dlls/crypt32/decode.c b/dlls/crypt32/decode.c index 465400812ef..6cb504777c1 100644 --- a/dlls/crypt32/decode.c +++ b/dlls/crypt32/decode.c @@ -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) diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c index 0d615ccae14..ca94a2e2e8c 100644 --- a/dlls/crypt32/msg.c +++ b/dlls/crypt32/msg.c @@ -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; -- 2.11.4.GIT