From 11da87d09820044ec3ca2242b840cb694f4ba6fd Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Thu, 1 Jun 2006 20:24:34 +0100 Subject: [PATCH] rpcrt4: NdrClientInitializeNew shouldn't clear all of the stub message, only selected fields. --- dlls/rpcrt4/ndr_midl.c | 52 ++++++++++++++----- dlls/rpcrt4/tests/ndr_marshall.c | 87 ++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 13 deletions(-) diff --git a/dlls/rpcrt4/ndr_midl.c b/dlls/rpcrt4/ndr_midl.c index b6665f61598..3ac0aedb735 100644 --- a/dlls/rpcrt4/ndr_midl.c +++ b/dlls/rpcrt4/ndr_midl.c @@ -188,21 +188,47 @@ void WINAPI NdrClientInitializeNew( PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE assert( pRpcMessage && pStubMsg && pStubDesc ); - memset(pRpcMessage, 0, sizeof(RPC_MESSAGE)); - pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION; - - /* not everyone allocates stack space for w2kReserved */ - memset(pStubMsg, 0, FIELD_OFFSET(MIDL_STUB_MESSAGE,pCSInfo)); - - pStubMsg->ReuseBuffer = FALSE; - pStubMsg->IsClient = TRUE; - pStubMsg->StubDesc = pStubDesc; - pStubMsg->pfnAllocate = pStubDesc->pfnAllocate; - pStubMsg->pfnFree = pStubDesc->pfnFree; - pStubMsg->RpcMsg = pRpcMessage; - + pRpcMessage->Handle = NULL; pRpcMessage->ProcNum = ProcNum; pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation; + pRpcMessage->RpcFlags = 0; + pRpcMessage->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION; + + pStubMsg->RpcMsg = pRpcMessage; + pStubMsg->BufferStart = NULL; + pStubMsg->BufferEnd = NULL; + pStubMsg->BufferLength = 0; + pStubMsg->IsClient = TRUE; + pStubMsg->ReuseBuffer = FALSE; + pStubMsg->pAllocAllNodesContext = NULL; + pStubMsg->pPointerQueueState = NULL; + pStubMsg->IgnoreEmbeddedPointers = 0; + pStubMsg->PointerBufferMark = NULL; + pStubMsg->fBufferValid = 0; + pStubMsg->uFlags = 0; + pStubMsg->pfnAllocate = pStubDesc->pfnAllocate; + pStubMsg->pfnFree = pStubDesc->pfnFree; + pStubMsg->StackTop = NULL; + pStubMsg->StubDesc = pStubDesc; + pStubMsg->FullPtrRefId = 0; + pStubMsg->PointerLength = 0; + pStubMsg->fInDontFree = 0; + pStubMsg->fDontCallFreeInst = 0; + pStubMsg->fInOnlyParam = 0; + pStubMsg->fHasReturn = 0; + pStubMsg->fHasExtensions = 0; + pStubMsg->fHasNewCorrDesc = 0; + pStubMsg->fUnused = 0; + pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE; + pStubMsg->pvDestContext = NULL; + pStubMsg->pRpcChannelBuffer = NULL; + pStubMsg->pArrayInfo = NULL; + pStubMsg->dwStubPhase = 0; + /* FIXME: LowStackMark */ + pStubMsg->pAsyncMsg = NULL; + pStubMsg->pCorrInfo = NULL; + pStubMsg->pCorrMemory = NULL; + pStubMsg->pMemoryList = NULL; } /*********************************************************************** diff --git a/dlls/rpcrt4/tests/ndr_marshall.c b/dlls/rpcrt4/tests/ndr_marshall.c index 0a70b9af5c2..ca9f5fdcde8 100644 --- a/dlls/rpcrt4/tests/ndr_marshall.c +++ b/dlls/rpcrt4/tests/ndr_marshall.c @@ -815,9 +815,96 @@ static void test_fullpointer_xlat(void) NdrFullPointerXlatFree(pXlatTables); } +static void test_client_init(void) +{ + MIDL_STUB_MESSAGE stubMsg; + RPC_MESSAGE rpcMsg; + + memset(&stubMsg, 0xcc, sizeof(stubMsg)); + + NdrClientInitializeNew(&rpcMsg, &stubMsg, &Object_StubDesc, 1); + +#define TEST_ZERO(field, fmt) ok(stubMsg.field == 0, #field " should have be set to zero instead of " fmt "\n", stubMsg.field) +#define TEST_POINTER_UNSET(field) ok(stubMsg.field == (void *)0xcccccccc, #field " should have be unset instead of %p\n", stubMsg.field) +#define TEST_ULONG_UNSET(field) ok(stubMsg.field == 0xcccccccc, #field " should have be unset instead of 0x%lx\n", stubMsg.field) + + ok(stubMsg.RpcMsg == &rpcMsg, "stubMsg.RpcMsg should have been %p instead of %p\n", &rpcMsg, stubMsg.RpcMsg); + TEST_POINTER_UNSET(Buffer); + TEST_ZERO(BufferStart, "%p"); + TEST_ZERO(BufferEnd, "%p"); + TEST_POINTER_UNSET(BufferMark); + TEST_ZERO(BufferLength, "%ld"); + TEST_ULONG_UNSET(MemorySize); + TEST_POINTER_UNSET(Memory); + ok(stubMsg.IsClient == 1, "stubMsg.IsClient should have been 1 instead of %u\n", stubMsg.IsClient); + TEST_ZERO(ReuseBuffer, "%d"); + TEST_ZERO(pAllocAllNodesContext, "%p"); + TEST_ZERO(pPointerQueueState, "%p"); + TEST_ZERO(IgnoreEmbeddedPointers, "%d"); + TEST_ZERO(PointerBufferMark, "%p"); + TEST_ZERO(fBufferValid, "%d"); + TEST_ZERO(uFlags, "%d"); + /* FIXME: UniquePtrCount */ + TEST_ULONG_UNSET(MaxCount); + TEST_ULONG_UNSET(Offset); + TEST_ULONG_UNSET(ActualCount); + ok(stubMsg.pfnAllocate == my_alloc, "stubMsg.pfnAllocate should have been %p instead of %p\n", my_alloc, stubMsg.pfnAllocate); + ok(stubMsg.pfnFree == my_free, "stubMsg.pfnFree should have been %p instead of %p\n", my_free, stubMsg.pfnFree); + TEST_ZERO(StackTop, "%p"); + TEST_POINTER_UNSET(pPresentedType); + TEST_POINTER_UNSET(pTransmitType); + TEST_POINTER_UNSET(SavedHandle); + ok(stubMsg.StubDesc == &Object_StubDesc, "stubMsg.StubDesc should have been %p instead of %p\n", &Object_StubDesc, stubMsg.StubDesc); + TEST_POINTER_UNSET(FullPtrXlatTables); + TEST_ZERO(FullPtrRefId, "%ld"); + TEST_ZERO(PointerLength, "%ld"); + TEST_ZERO(fInDontFree, "%d"); + TEST_ZERO(fDontCallFreeInst, "%d"); + TEST_ZERO(fInOnlyParam, "%d"); + TEST_ZERO(fHasReturn, "%d"); + TEST_ZERO(fHasExtensions, "%d"); + TEST_ZERO(fHasNewCorrDesc, "%d"); + TEST_ZERO(fUnused, "%d"); + ok(stubMsg.fUnused2 == 0xffffcccc, "stubMsg.fUnused2 should have been 0xcccc instead of 0x%x\n", stubMsg.fUnused2); + ok(stubMsg.dwDestContext == MSHCTX_DIFFERENTMACHINE, "stubMsg.dwDestContext should have been MSHCTX_DIFFERENTMACHINE instead of %ld\n", stubMsg.dwDestContext); + TEST_ZERO(pvDestContext, "%p"); + TEST_POINTER_UNSET(SavedContextHandles); + TEST_ULONG_UNSET(ParamNumber); + TEST_ZERO(pRpcChannelBuffer, "%p"); + TEST_ZERO(pArrayInfo, "%p"); + TEST_POINTER_UNSET(SizePtrCountArray); + TEST_POINTER_UNSET(SizePtrOffsetArray); + TEST_POINTER_UNSET(SizePtrLengthArray); + TEST_POINTER_UNSET(pArgQueue); + TEST_ZERO(dwStubPhase, "%ld"); + /* FIXME: where does this value come from? */ + trace("LowStackMark is %p\n", stubMsg.LowStackMark); + TEST_ZERO(pAsyncMsg, "%p"); + TEST_ZERO(pCorrInfo, "%p"); + TEST_ZERO(pCorrMemory, "%p"); + TEST_ZERO(pMemoryList, "%p"); + TEST_POINTER_UNSET(pCSInfo); + TEST_POINTER_UNSET(ConformanceMark); + TEST_POINTER_UNSET(VarianceMark); + ok(stubMsg.Unused == 0xcccccccc, "Unused should have be unset instead of 0x%x\n", stubMsg.Unused); + TEST_POINTER_UNSET(pContext); +#if 0 + TEST_ULONG_UNSET(Reserved51_1); + TEST_ULONG_UNSET(Reserved51_2); + TEST_ULONG_UNSET(Reserved51_3); + TEST_ULONG_UNSET(Reserved51_4); + TEST_ULONG_UNSET(Reserved51_5); +#endif +#undef TEST_ULONG_UNSET +#undef TEST_POINTER_UNSET +#undef TEST_ZERO + +} + START_TEST( ndr_marshall ) { test_simple_types(); test_simple_struct(); test_fullpointer_xlat(); + test_client_init(); }