From 2eca96af67c607ad4c41f75794005471f1423e49 Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Sun, 8 Feb 2009 18:00:26 +0000 Subject: [PATCH] ole32: Fix CLIPFORMAT marshalling on 64-bit platforms by not using the wireCLIPFORMAT type. The wireCLIPFORMAT represents the memory equivalent format of the wire format and not the wire format itself. Also update the tests to do the same. --- dlls/ole32/tests/usrmarshal.c | 12 +++----- dlls/ole32/usrmarshal.c | 71 +++++++++++++++++++++++++++---------------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/dlls/ole32/tests/usrmarshal.c b/dlls/ole32/tests/usrmarshal.c index cbb7dc3658b..ef588ee8f08 100644 --- a/dlls/ole32/tests/usrmarshal.c +++ b/dlls/ole32/tests/usrmarshal.c @@ -95,25 +95,23 @@ static void test_marshal_CLIPFORMAT(void) RPC_MESSAGE rpc_msg; unsigned char *buffer; ULONG size; - wireCLIPFORMAT wirecf; CLIPFORMAT cf = RegisterClipboardFormatA("MyFormat"); CLIPFORMAT cf2; init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE); size = CLIPFORMAT_UserSize(&umcb.Flags, 0, &cf); - ok(size == sizeof(*wirecf) + sizeof(cf_marshaled), "Wrong size %d\n", size); + ok(size == 8 + sizeof(cf_marshaled), "CLIPFORMAT: Wrong size %d\n", size); buffer = HeapAlloc(GetProcessHeap(), 0, size); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE); CLIPFORMAT_UserMarshal(&umcb.Flags, buffer, &cf); - wirecf = (wireCLIPFORMAT)buffer; - ok(wirecf->fContext == WDT_REMOTE_CALL, "Context should be WDT_REMOTE_CALL instead of 0x%08lx\n", wirecf->fContext); - ok(wirecf->u.dwValue == cf, "Marshaled value should be 0x%04x instead of 0x%04x\n", cf, wirecf->u.dwValue); - ok(!memcmp(wirecf+1, cf_marshaled, sizeof(cf_marshaled)), "Marshaled data differs\n"); + ok(*(LONG *)(buffer + 0) == WDT_REMOTE_CALL, "CLIPFORMAT: Context should be WDT_REMOTE_CALL instead of 0x%08x\n", *(LONG *)(buffer + 0)); + ok(*(DWORD *)(buffer + 4) == cf, "CLIPFORMAT: Marshaled value should be 0x%04x instead of 0x%04x\n", cf, *(DWORD *)(buffer + 4)); + ok(!memcmp(buffer + 8, cf_marshaled, sizeof(cf_marshaled)), "Marshaled data differs\n"); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE); CLIPFORMAT_UserUnmarshal(&umcb.Flags, buffer, &cf2); - ok(cf == cf2, "Didn't unmarshal properly\n"); + ok(cf == cf2, "CLIPFORMAT: Didn't unmarshal properly\n"); HeapFree(GetProcessHeap(), 0, buffer); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE); diff --git a/dlls/ole32/usrmarshal.c b/dlls/ole32/usrmarshal.c index 3af71df8a88..afe456bb597 100644 --- a/dlls/ole32/usrmarshal.c +++ b/dlls/ole32/usrmarshal.c @@ -105,7 +105,7 @@ ULONG __RPC_USER CLIPFORMAT_UserSize(ULONG *pFlags, ULONG StartingSize, CLIPFORM TRACE("(%s, %d, %p\n", debugstr_user_flags(pFlags), StartingSize, pCF); - size += sizeof(userCLIPFORMAT); + size += 8; /* only need to marshal the name if it is not a pre-defined type and * we are going remote */ @@ -113,7 +113,7 @@ ULONG __RPC_USER CLIPFORMAT_UserSize(ULONG *pFlags, ULONG StartingSize, CLIPFORM { WCHAR format[255]; INT ret; - size += 3 * sizeof(INT); + size += 3 * sizeof(UINT); /* urg! this function is badly designed because it won't tell us how * much space is needed without doing a dummy run of storing the * name into a buffer */ @@ -146,30 +146,30 @@ ULONG __RPC_USER CLIPFORMAT_UserSize(ULONG *pFlags, ULONG StartingSize, CLIPFORM */ unsigned char * __RPC_USER CLIPFORMAT_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, CLIPFORMAT *pCF) { - wireCLIPFORMAT wirecf = (wireCLIPFORMAT)pBuffer; - TRACE("(%s, %p, &0x%04x\n", debugstr_user_flags(pFlags), pBuffer, *pCF); - wirecf->u.dwValue = *pCF; - pBuffer += sizeof(*wirecf); - /* only need to marshal the name if it is not a pre-defined type and * we are going remote */ if ((*pCF >= 0xc000) && (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE)) { WCHAR format[255]; - INT len; - wirecf->fContext = WDT_REMOTE_CALL; + UINT len; + + *(DWORD *)pBuffer = WDT_REMOTE_CALL; + pBuffer += 4; + *(DWORD *)pBuffer = *pCF; + pBuffer += 4; + len = GetClipboardFormatNameW(*pCF, format, sizeof(format)/sizeof(format[0])-1); if (!len) RaiseException(DV_E_CLIPFORMAT, 0, 0, NULL); len += 1; - *(INT *)pBuffer = len; - pBuffer += sizeof(INT); - *(INT *)pBuffer = 0; - pBuffer += sizeof(INT); - *(INT *)pBuffer = len; - pBuffer += sizeof(INT); + *(UINT *)pBuffer = len; + pBuffer += sizeof(UINT); + *(UINT *)pBuffer = 0; + pBuffer += sizeof(UINT); + *(UINT *)pBuffer = len; + pBuffer += sizeof(UINT); TRACE("marshaling format name %s\n", debugstr_wn(format, len-1)); lstrcpynW((LPWSTR)pBuffer, format, len); pBuffer += len * sizeof(WCHAR); @@ -177,7 +177,12 @@ unsigned char * __RPC_USER CLIPFORMAT_UserMarshal(ULONG *pFlags, unsigned char * pBuffer += sizeof(WCHAR); } else - wirecf->fContext = WDT_INPROC_CALL; + { + *(DWORD *)pBuffer = WDT_INPROC_CALL; + pBuffer += 4; + *(DWORD *)pBuffer = *pCF; + pBuffer += 4; + } return pBuffer; } @@ -203,24 +208,36 @@ unsigned char * __RPC_USER CLIPFORMAT_UserMarshal(ULONG *pFlags, unsigned char * */ unsigned char * __RPC_USER CLIPFORMAT_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, CLIPFORMAT *pCF) { - wireCLIPFORMAT wirecf = (wireCLIPFORMAT)pBuffer; + LONG fContext; TRACE("(%s, %p, %p\n", debugstr_user_flags(pFlags), pBuffer, pCF); - pBuffer += sizeof(*wirecf); - if (wirecf->fContext == WDT_INPROC_CALL) - *pCF = (CLIPFORMAT)wirecf->u.dwValue; - else if (wirecf->fContext == WDT_REMOTE_CALL) + fContext = *(DWORD *)pBuffer; + pBuffer += 4; + + if (fContext == WDT_INPROC_CALL) + { + *pCF = *(CLIPFORMAT *)pBuffer; + pBuffer += 4; + } + else if (fContext == WDT_REMOTE_CALL) { CLIPFORMAT cf; - INT len = *(INT *)pBuffer; - pBuffer += sizeof(INT); - if (*(INT *)pBuffer != 0) + UINT len; + + /* pointer ID for registered clip format string */ + if (*(DWORD *)pBuffer == 0) + RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL); + pBuffer += 4; + + len = *(UINT *)pBuffer; + pBuffer += sizeof(UINT); + if (*(UINT *)pBuffer != 0) RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL); - pBuffer += sizeof(INT); - if (*(INT *)pBuffer != len) + pBuffer += sizeof(UINT); + if (*(UINT *)pBuffer != len) RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL); - pBuffer += sizeof(INT); + pBuffer += sizeof(UINT); if (((WCHAR *)pBuffer)[len] != '\0') RaiseException(RPC_S_INVALID_BOUND, 0, 0, NULL); TRACE("unmarshaling clip format %s\n", debugstr_w((LPCWSTR)pBuffer)); -- 2.11.4.GIT