From 7ddc1b9e2d2696e80a3d9e81e96dc5a0ff81b738 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 18 Sep 2013 14:03:07 -0400 Subject: [PATCH] Avoid type-issues generating wrong GlobCnt - leading to OpenChange crashes during the sync process. --- OpenChange/MAPIStoreGCSFolder.m | 4 +++- OpenChange/MAPIStoreObject.m | 3 +++ OpenChange/NSData+MAPIStore.m | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/OpenChange/MAPIStoreGCSFolder.m b/OpenChange/MAPIStoreGCSFolder.m index 750a255a4..52d2b0866 100644 --- a/OpenChange/MAPIStoreGCSFolder.m +++ b/OpenChange/MAPIStoreGCSFolder.m @@ -259,7 +259,6 @@ static Class NSNumberK; } } */ - - (void) _setChangeKey: (NSData *) changeKey forMessageEntry: (NSMutableDictionary *) messageEntry inChangeListOnly: (BOOL) inChangeListOnly @@ -462,6 +461,9 @@ static Class NSNumberK; [messageEntry setObject: changeNumber forKey: @"version"]; newChangeNum = [changeNumber unsignedLongLongValue]; + + // A GLOBCNT structure is a 6-byte global namespace counter, + // we strip the first 2 bytes. The first two bytes is the ReplicaId changeKey = [self getReplicaKeyFromGlobCnt: newChangeNum >> 16]; [self _setChangeKey: changeKey forMessageEntry: messageEntry inChangeListOnly: NO]; diff --git a/OpenChange/MAPIStoreObject.m b/OpenChange/MAPIStoreObject.m index 7d4bb3219..1d468915c 100644 --- a/OpenChange/MAPIStoreObject.m +++ b/OpenChange/MAPIStoreObject.m @@ -284,6 +284,9 @@ static Class NSExceptionK, MAPIStoreFolderK; return MAPISTORE_SUCCESS; } +// +// The GlobCnt is 6 bytes long. +// - (NSData *) getReplicaKeyFromGlobCnt: (uint64_t) objectCnt { struct mapistore_connection_info *connInfo; diff --git a/OpenChange/NSData+MAPIStore.m b/OpenChange/NSData+MAPIStore.m index b2bdedc97..44b6dcf85 100644 --- a/OpenChange/NSData+MAPIStore.m +++ b/OpenChange/NSData+MAPIStore.m @@ -148,6 +148,7 @@ static void _fillFlatUIDWithGUID (struct FlatUID_r *flatUID, const struct GUID * - (struct XID *) asXIDInMemCtx: (void *) memCtx { struct XID *xid; + uint8_t *bytes; NSUInteger max; max = [self length]; @@ -158,7 +159,9 @@ static void _fillFlatUIDWithGUID (struct FlatUID_r *flatUID, const struct GUID * [self _extractGUID: &xid->GUID]; xid->Size = max - 16; - xid->Data = talloc_memdup (xid, [self bytes] + 16, xid->Size); + + bytes = (uint8_t *) [self bytes]; + xid->Data = talloc_memdup (xid, (bytes+16), xid->Size); } else {