rpcrt4: Fix NdrConformantVaryingStructUnmarshall to use buffer memory if applicable...
authorRob Shearman <robertshearman@gmail.com>
Mon, 23 Jun 2008 11:56:49 +0000 (12:56 +0100)
committerAlexandre Julliard <julliard@winehq.org>
Mon, 23 Jun 2008 17:46:29 +0000 (19:46 +0200)
dlls/rpcrt4/ndr_marshall.c
dlls/rpcrt4/tests/server.c

index 977effaaa486592e31841148c06a09e0d0e045d1..4e7643ac6255cfd6a6f5e68b8439093fedb548a6 100644 (file)
@@ -1562,7 +1562,7 @@ static unsigned char * EmbeddedPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,
  *           EmbeddedPointerUnmarshall
  */
 static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
-                                                 unsigned char *pDstMemoryPtrs,
+                                                 unsigned char *pDstBuffer,
                                                  unsigned char *pSrcMemoryPtrs,
                                                  PFORMAT_STRING pFormat,
                                                  unsigned char fMustAlloc)
@@ -1572,7 +1572,7 @@ static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
   unsigned i;
   unsigned char *saved_buffer = NULL;
 
-  TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, pDstMemoryPtrs, pSrcMemoryPtrs, pFormat, fMustAlloc);
+  TRACE("(%p,%p,%p,%p,%d)\n", pStubMsg, pDstBuffer, pSrcMemoryPtrs, pFormat, fMustAlloc);
 
   if (*pFormat != RPC_FC_PP) return NULL;
   pFormat += 2;
@@ -1610,16 +1610,16 @@ static unsigned char * EmbeddedPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
     }
     for (i = 0; i < rep; i++) {
       PFORMAT_STRING info = pFormat;
-      unsigned char *memdstbase = pDstMemoryPtrs + (i * stride);
+      unsigned char *bufdstbase = pDstBuffer + (i * stride);
       unsigned char *memsrcbase = pSrcMemoryPtrs + (i * stride);
       unsigned char *bufbase = Mark + (i * stride);
       unsigned u;
 
       for (u=0; u<count; u++,info+=8) {
-        unsigned char **memdstptr = (unsigned char **)(memdstbase + *(const SHORT*)&info[0]);
+        unsigned char **bufdstptr = (unsigned char **)(bufdstbase + *(const SHORT*)&info[2]);
         unsigned char **memsrcptr = (unsigned char **)(memsrcbase + *(const SHORT*)&info[0]);
         unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];
-        PointerUnmarshall(pStubMsg, bufptr, memdstptr, *memsrcptr, info+4, fMustAlloc);
+        PointerUnmarshall(pStubMsg, bufptr, bufdstptr, *memsrcptr, info+4, fMustAlloc);
       }
     }
     pFormat += 8 * count;
@@ -4186,6 +4186,7 @@ unsigned char *  WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE
     PFORMAT_STRING pCVArrayFormat;
     ULONG esize, bufsize;
     unsigned char cvarray_type;
+    unsigned char *saved_buffer, *saved_array_buffer;
 
     TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
 
@@ -4237,9 +4238,9 @@ unsigned char *  WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE
         *ppMemory = NdrAllocate(pStubMsg, size);
     }
 
-    /* copy the constant data */
-    pStubMsg->BufferMark = pStubMsg->Buffer;
-    safe_copy_from_buffer(pStubMsg, *ppMemory, pCVStructFormat->memory_size);
+    /* mark the start of the constant data */
+    saved_buffer = pStubMsg->BufferMark = pStubMsg->Buffer;
+    safe_buffer_increment(pStubMsg, pCVStructFormat->memory_size);
 
     pCVArrayFormat = ReadVariance(pStubMsg, pCVArrayFormat, pStubMsg->MaxCount);
 
@@ -4249,16 +4250,23 @@ unsigned char *  WINAPI NdrConformantVaryingStructUnmarshall(PMIDL_STUB_MESSAGE
         (cvarray_type == RPC_FC_C_WSTRING))
         validate_string_data(pStubMsg, bufsize, esize);
 
+    /* mark the start of the array data */
+    saved_array_buffer = pStubMsg->Buffer;
+    safe_buffer_increment(pStubMsg, bufsize);
+
+    EmbeddedPointerUnmarshall(pStubMsg, saved_buffer, *ppMemory, pFormat, fMustAlloc);
+
+    /* copy the constant data */
+    memcpy(*ppMemory, saved_buffer, pCVStructFormat->memory_size);
     /* copy the array data */
-    safe_copy_from_buffer(pStubMsg, *ppMemory + pCVStructFormat->memory_size, bufsize);
+    TRACE("copying %p to %p\n", saved_array_buffer, *ppMemory + pCVStructFormat->memory_size);
+    memcpy(*ppMemory + pCVStructFormat->memory_size, saved_array_buffer, bufsize);
 
     if (cvarray_type == RPC_FC_C_CSTRING)
         TRACE("string=%s\n", debugstr_a((char *)(*ppMemory + pCVStructFormat->memory_size)));
     else if (cvarray_type == RPC_FC_C_WSTRING)
         TRACE("string=%s\n", debugstr_w((WCHAR *)(*ppMemory + pCVStructFormat->memory_size)));
 
-    EmbeddedPointerUnmarshall(pStubMsg, *ppMemory, *ppMemory, pFormat, TRUE /* FIXME */);
-
     return NULL;
 }
 
index 91c87bf52bfa71b422d630d69d8ef35c2c0eb799..69b9ba40db3caeed9716872117769317436d5f97 100644 (file)
@@ -1208,9 +1208,7 @@ array_tests(void)
   ns->size = 5;
   ns->numbers[0].pi = pi;
   get_numbers_struct(&ns);
-  todo_wine {
   ok(ns->numbers[0].pi == pi, "RPC conformant varying struct embedded pointer changed from %p to %p\n", pi, ns->numbers[0].pi);
-  }
   ok(*ns->numbers[0].pi == 5, "pi unmarshalled incorrectly %d\n", *ns->numbers[0].pi);
 
   HeapFree(GetProcessHeap(), 0, ns);