crypt32: Fix the aligning up to a DWORD_PTR boundary.
Michael Stefaniuc
mstefani at redhat.de
Thu Nov 6 18:01:39 CST 2008
---
Juan,
can you please have a look at the attached patch?
The comments were claiming that pointers were rounded up to a DWORD_PTR
boundary but with the exception of decode.c that didn't actually happen.
The tests pass without problems so I ASSume the patch is correct. If not
I'll blame it on the lack of sleep... ;)
bye
michael
dlls/crypt32/crypt32_private.h | 11 +++++++++++
dlls/crypt32/decode.c | 4 +---
dlls/crypt32/msg.c | 26 ++++++++------------------
3 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h
index 46bc8c5..23c4a7d 100644
--- a/dlls/crypt32/crypt32_private.h
+++ b/dlls/crypt32/crypt32_private.h
@@ -374,4 +374,15 @@ 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 4654008..6cb5047 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 0d615cc..ca94a2e 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;
--
1.6.0.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20081107/69f302b5/attachment-0001.pgp
More information about the wine-patches
mailing list