Commit eb810fbb authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

ole32: Properly align HANDLE marshal data.

parent 8c6b8bf4
...@@ -225,25 +225,27 @@ static void test_marshal_HWND(void) ...@@ -225,25 +225,27 @@ static void test_marshal_HWND(void)
USER_MARSHAL_CB umcb; USER_MARSHAL_CB umcb;
MIDL_STUB_MESSAGE stub_msg; MIDL_STUB_MESSAGE stub_msg;
RPC_MESSAGE rpc_msg; RPC_MESSAGE rpc_msg;
unsigned char *buffer; unsigned char *buffer, *buffer_end;
ULONG size; ULONG size;
HWND hwnd = GetDesktopWindow(); HWND hwnd = GetDesktopWindow();
HWND hwnd2; HWND hwnd2;
wireHWND wirehwnd; wireHWND wirehwnd;
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
size = HWND_UserSize(&umcb.Flags, 0, &hwnd); size = HWND_UserSize(&umcb.Flags, 1, &hwnd);
ok(size == sizeof(*wirehwnd), "Wrong size %d\n", size); ok(size == 4 + sizeof(*wirehwnd), "Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size); buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HWND_UserMarshal(&umcb.Flags, buffer, &hwnd); buffer_end = HWND_UserMarshal(&umcb.Flags, buffer + 1, &hwnd);
wirehwnd = (wireHWND)buffer; ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
wirehwnd = (wireHWND)(buffer + 4);
ok(wirehwnd->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehwnd->fContext); ok(wirehwnd->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehwnd->fContext);
ok(wirehwnd->u.hInproc == (LONG_PTR)hwnd, "Marshaled value should be %p instead of %x\n", hwnd, wirehwnd->u.hRemote); ok(wirehwnd->u.hInproc == (LONG_PTR)hwnd, "Marshaled value should be %p instead of %x\n", hwnd, wirehwnd->u.hRemote);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HWND_UserUnmarshal(&umcb.Flags, buffer, &hwnd2); buffer_end = HWND_UserUnmarshal(&umcb.Flags, buffer + 1, &hwnd2);
ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
ok(hwnd == hwnd2, "Didn't unmarshal properly\n"); ok(hwnd == hwnd2, "Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer); HeapFree(GetProcessHeap(), 0, buffer);
...@@ -1092,23 +1094,25 @@ static void test_marshal_HDC(void) ...@@ -1092,23 +1094,25 @@ static void test_marshal_HDC(void)
HDC hdc = GetDC(0), hdc2; HDC hdc = GetDC(0), hdc2;
USER_MARSHAL_CB umcb; USER_MARSHAL_CB umcb;
RPC_MESSAGE rpc_msg; RPC_MESSAGE rpc_msg;
unsigned char *buffer; unsigned char *buffer, *buffer_end;
wireHDC wirehdc; wireHDC wirehdc;
ULONG size; ULONG size;
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
size = HDC_UserSize(&umcb.Flags, 0, &hdc); size = HDC_UserSize(&umcb.Flags, 1, &hdc);
ok(size == sizeof(*wirehdc), "Wrong size %d\n", size); ok(size == 4 + sizeof(*wirehdc), "Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size); buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HDC_UserMarshal(&umcb.Flags, buffer, &hdc); buffer_end = HDC_UserMarshal(&umcb.Flags, buffer + 1, &hdc);
wirehdc = (wireHDC)buffer; ok(buffer_end == buffer + 4 + sizeof(*wirehdc), "got %p buffer %p\n", buffer_end, buffer);
wirehdc = (wireHDC)(buffer + 4);
ok(wirehdc->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehdc->fContext); ok(wirehdc->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehdc->fContext);
ok(wirehdc->u.hInproc == (LONG_PTR)hdc, "Marshaled value should be %p instead of %x\n", hdc, wirehdc->u.hRemote); ok(wirehdc->u.hInproc == (LONG_PTR)hdc, "Marshaled value should be %p instead of %x\n", hdc, wirehdc->u.hRemote);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HDC_UserUnmarshal(&umcb.Flags, buffer, &hdc2); buffer_end = HDC_UserUnmarshal(&umcb.Flags, buffer + 1, &hdc2);
ok(buffer_end == buffer + 4 + sizeof(*wirehdc), "got %p buffer %p\n", buffer_end, buffer);
ok(hdc == hdc2, "Didn't unmarshal properly\n"); ok(hdc == hdc2, "Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer); HeapFree(GetProcessHeap(), 0, buffer);
...@@ -1124,7 +1128,7 @@ static void test_marshal_HICON(void) ...@@ -1124,7 +1128,7 @@ static void test_marshal_HICON(void)
HICON hIcon, hIcon2; HICON hIcon, hIcon2;
USER_MARSHAL_CB umcb; USER_MARSHAL_CB umcb;
RPC_MESSAGE rpc_msg; RPC_MESSAGE rpc_msg;
unsigned char *buffer; unsigned char *buffer, *buffer_end;
wireHICON wirehicon; wireHICON wirehicon;
ULONG size; ULONG size;
...@@ -1132,18 +1136,20 @@ static void test_marshal_HICON(void) ...@@ -1132,18 +1136,20 @@ static void test_marshal_HICON(void)
ok(hIcon != 0, "CreateIcon failed\n"); ok(hIcon != 0, "CreateIcon failed\n");
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
size = HICON_UserSize(&umcb.Flags, 0, &hIcon); size = HICON_UserSize(&umcb.Flags, 1, &hIcon);
ok(size == sizeof(*wirehicon), "Wrong size %d\n", size); ok(size == 4 + sizeof(*wirehicon), "Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size); buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HICON_UserMarshal(&umcb.Flags, buffer, &hIcon); buffer_end = HICON_UserMarshal(&umcb.Flags, buffer + 1, &hIcon);
wirehicon = (wireHICON)buffer; ok(buffer_end == buffer + 4 + sizeof(*wirehicon), "got %p buffer %p\n", buffer_end, buffer);
wirehicon = (wireHICON)(buffer + 4);
ok(wirehicon->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehicon->fContext); ok(wirehicon->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehicon->fContext);
ok(wirehicon->u.hInproc == (LONG_PTR)hIcon, "Marshaled value should be %p instead of %x\n", hIcon, wirehicon->u.hRemote); ok(wirehicon->u.hInproc == (LONG_PTR)hIcon, "Marshaled value should be %p instead of %x\n", hIcon, wirehicon->u.hRemote);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HICON_UserUnmarshal(&umcb.Flags, buffer, &hIcon2); buffer_end = HICON_UserUnmarshal(&umcb.Flags, buffer + 1, &hIcon2);
ok(buffer_end == buffer + 4 + sizeof(*wirehicon), "got %p buffer %p\n", buffer_end, buffer);
ok(hIcon == hIcon2, "Didn't unmarshal properly\n"); ok(hIcon == hIcon2, "Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer); HeapFree(GetProcessHeap(), 0, buffer);
...@@ -1158,7 +1164,7 @@ static void test_marshal_HBRUSH(void) ...@@ -1158,7 +1164,7 @@ static void test_marshal_HBRUSH(void)
HBRUSH hBrush, hBrush2; HBRUSH hBrush, hBrush2;
USER_MARSHAL_CB umcb; USER_MARSHAL_CB umcb;
RPC_MESSAGE rpc_msg; RPC_MESSAGE rpc_msg;
unsigned char *buffer; unsigned char *buffer, *buffer_end;
LOGBRUSH logbrush; LOGBRUSH logbrush;
wireHBRUSH wirehbrush; wireHBRUSH wirehbrush;
ULONG size; ULONG size;
...@@ -1171,18 +1177,20 @@ static void test_marshal_HBRUSH(void) ...@@ -1171,18 +1177,20 @@ static void test_marshal_HBRUSH(void)
ok(hBrush != 0, "CreateBrushIndirect failed\n"); ok(hBrush != 0, "CreateBrushIndirect failed\n");
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
size = HBRUSH_UserSize(&umcb.Flags, 0, &hBrush); size = HBRUSH_UserSize(&umcb.Flags, 1, &hBrush);
ok(size == sizeof(*wirehbrush), "Wrong size %d\n", size); ok(size == 4 + sizeof(*wirehbrush), "Wrong size %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size); buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HBRUSH_UserMarshal(&umcb.Flags, buffer, &hBrush); buffer_end = HBRUSH_UserMarshal(&umcb.Flags, buffer + 1, &hBrush);
wirehbrush = (wireHBRUSH)buffer; ok(buffer_end == buffer + 4 + sizeof(*wirehbrush), "got %p buffer %p\n", buffer_end, buffer);
wirehbrush = (wireHBRUSH)(buffer + 4);
ok(wirehbrush->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehbrush->fContext); ok(wirehbrush->fContext == WDT_INPROC_CALL, "Context should be WDT_INPROC_CALL instead of 0x%08x\n", wirehbrush->fContext);
ok(wirehbrush->u.hInproc == (LONG_PTR)hBrush, "Marshaled value should be %p instead of %x\n", hBrush, wirehbrush->u.hRemote); ok(wirehbrush->u.hInproc == (LONG_PTR)hBrush, "Marshaled value should be %p instead of %x\n", hBrush, wirehbrush->u.hRemote);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL); init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
HBRUSH_UserUnmarshal(&umcb.Flags, buffer, &hBrush2); buffer_end = HBRUSH_UserUnmarshal(&umcb.Flags, buffer + 1, &hBrush2);
ok(buffer_end == buffer + 4 + sizeof(*wirehbrush), "got %p buffer %p\n", buffer_end, buffer);
ok(hBrush == hBrush2, "Didn't unmarshal properly\n"); ok(hBrush == hBrush2, "Didn't unmarshal properly\n");
HeapFree(GetProcessHeap(), 0, buffer); HeapFree(GetProcessHeap(), 0, buffer);
......
...@@ -286,18 +286,23 @@ static ULONG handle_UserSize(ULONG *pFlags, ULONG StartingSize, HANDLE *handle) ...@@ -286,18 +286,23 @@ static ULONG handle_UserSize(ULONG *pFlags, ULONG StartingSize, HANDLE *handle)
RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL); RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
return StartingSize; return StartingSize;
} }
ALIGN_LENGTH(StartingSize, 3);
return StartingSize + sizeof(RemotableHandle); return StartingSize + sizeof(RemotableHandle);
} }
static unsigned char * handle_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HANDLE *handle) static unsigned char * handle_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, HANDLE *handle)
{ {
RemotableHandle *remhandle = (RemotableHandle *)pBuffer; RemotableHandle *remhandle;
if (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE) if (LOWORD(*pFlags) == MSHCTX_DIFFERENTMACHINE)
{ {
ERR("can't remote a local handle\n"); ERR("can't remote a local handle\n");
RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL); RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);
return pBuffer; return pBuffer;
} }
ALIGN_POINTER(pBuffer, 3);
remhandle = (RemotableHandle *)pBuffer;
remhandle->fContext = WDT_INPROC_CALL; remhandle->fContext = WDT_INPROC_CALL;
remhandle->u.hInproc = (LONG_PTR)*handle; remhandle->u.hInproc = (LONG_PTR)*handle;
return pBuffer + sizeof(RemotableHandle); return pBuffer + sizeof(RemotableHandle);
...@@ -305,7 +310,10 @@ static unsigned char * handle_UserMarshal(ULONG *pFlags, unsigned char *pBuffer, ...@@ -305,7 +310,10 @@ static unsigned char * handle_UserMarshal(ULONG *pFlags, unsigned char *pBuffer,
static unsigned char * handle_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HANDLE *handle) static unsigned char * handle_UserUnmarshal(ULONG *pFlags, unsigned char *pBuffer, HANDLE *handle)
{ {
RemotableHandle *remhandle = (RemotableHandle *)pBuffer; RemotableHandle *remhandle;
ALIGN_POINTER(pBuffer, 3);
remhandle = (RemotableHandle *)pBuffer;
if (remhandle->fContext != WDT_INPROC_CALL) if (remhandle->fContext != WDT_INPROC_CALL)
RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL); RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
*handle = (HANDLE)(LONG_PTR)remhandle->u.hInproc; *handle = (HANDLE)(LONG_PTR)remhandle->u.hInproc;
......
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