Robert Shearman : rpcrt4: Correctly align the buffer to read/ write array data to.

Alexandre Julliard julliard at wine.codeweavers.com
Wed May 10 12:56:53 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 4b4192f3a58a3d2addc1f385114f91b377e61848
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=4b4192f3a58a3d2addc1f385114f91b377e61848

Author: Robert Shearman <rob at codeweavers.com>
Date:   Wed May 10 13:12:52 2006 +0100

rpcrt4: Correctly align the buffer to read/write array data to.

---

 dlls/rpcrt4/ndr_marshall.c |   46 +++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/dlls/rpcrt4/ndr_marshall.c b/dlls/rpcrt4/ndr_marshall.c
index 567ae0b..a4fa2d7 100644
--- a/dlls/rpcrt4/ndr_marshall.c
+++ b/dlls/rpcrt4/ndr_marshall.c
@@ -1906,6 +1906,8 @@ unsigned char * WINAPI NdrConformantArra
                                                   PFORMAT_STRING pFormat)
 {
   DWORD size = 0, esize = *(const WORD*)(pFormat+2);
+  unsigned char alignment = pFormat[1] + 1;
+
   TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
   if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
 
@@ -1915,6 +1917,8 @@ unsigned char * WINAPI NdrConformantArra
   NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, size);
   pStubMsg->Buffer += 4;
 
+  ALIGN_POINTER(pStubMsg->Buffer, alignment);
+
   memcpy(pStubMsg->Buffer, pMemory, size*esize);
   pStubMsg->BufferMark = pStubMsg->Buffer;
   pStubMsg->Buffer += size*esize;
@@ -1935,6 +1939,8 @@ unsigned char * WINAPI NdrConformantArra
                                                     unsigned char fMustAlloc)
 {
   DWORD size = 0, esize = *(const WORD*)(pFormat+2);
+  unsigned char alignment = pFormat[1] + 1;
+
   TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
   if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
 
@@ -1944,6 +1950,8 @@ unsigned char * WINAPI NdrConformantArra
   if (fMustAlloc || !*ppMemory)
     *ppMemory = NdrAllocate(pStubMsg, size*esize);
 
+  ALIGN_POINTER(pStubMsg->Buffer, alignment);
+
   memcpy(*ppMemory, pStubMsg->Buffer, size*esize);
 
   pStubMsg->BufferMark = pStubMsg->Buffer;
@@ -1962,14 +1970,19 @@ void WINAPI NdrConformantArrayBufferSize
                                          PFORMAT_STRING pFormat)
 {
   DWORD size = 0, esize = *(const WORD*)(pFormat+2);
+  unsigned char alignment = pFormat[1] + 1;
+
   TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
   if (pFormat[0] != RPC_FC_CARRAY) FIXME("format=%d\n", pFormat[0]);
 
   pFormat = ComputeConformance(pStubMsg, pMemory, pFormat+4, 0);
   size = pStubMsg->MaxCount;
+  pStubMsg->BufferLength += 4;
+
+  ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
 
   /* conformance value plus array */
-  pStubMsg->BufferLength += sizeof(DWORD) + size*esize;
+  pStubMsg->BufferLength += size*esize;
 
   EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
 }
@@ -2015,6 +2028,7 @@ unsigned char* WINAPI NdrConformantVaryi
                                                          unsigned char* pMemory,
                                                          PFORMAT_STRING pFormat )
 {
+    unsigned char alignment = pFormat[1] + 1;
     DWORD esize = *(const WORD*)(pFormat+2);
 
     TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
@@ -2036,6 +2050,8 @@ unsigned char* WINAPI NdrConformantVaryi
     NDR_LOCAL_UINT32_WRITE(pStubMsg->Buffer, pStubMsg->ActualCount);
     pStubMsg->Buffer += 4;
 
+    ALIGN_POINTER(pStubMsg->Buffer, alignment);
+
     memcpy(pStubMsg->Buffer, pMemory + pStubMsg->Offset, pStubMsg->ActualCount*esize);
     pStubMsg->BufferMark = pStubMsg->Buffer;
     pStubMsg->Buffer += pStubMsg->ActualCount*esize;
@@ -2056,6 +2072,7 @@ unsigned char* WINAPI NdrConformantVaryi
                                                            PFORMAT_STRING pFormat,
                                                            unsigned char fMustAlloc )
 {
+    unsigned char alignment = pFormat[1] + 1;
     DWORD esize = *(const WORD*)(pFormat+2);
 
     TRACE("(%p, %p, %p, %d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
@@ -2066,9 +2083,12 @@ unsigned char* WINAPI NdrConformantVaryi
         RpcRaiseException(RPC_S_INTERNAL_ERROR);
         return NULL;
     }
+
     pFormat = ReadConformance(pStubMsg, pFormat);
     pFormat = ReadVariance(pStubMsg, pFormat);
 
+    ALIGN_POINTER(pStubMsg->Buffer, alignment);
+
     if (!*ppMemory || fMustAlloc)
         *ppMemory = NdrAllocate(pStubMsg, pStubMsg->MaxCount * esize);
     memcpy(*ppMemory + pStubMsg->Offset, pStubMsg->Buffer, pStubMsg->ActualCount * esize);
@@ -2109,6 +2129,7 @@ void WINAPI NdrConformantVaryingArrayFre
 void WINAPI NdrConformantVaryingArrayBufferSize( PMIDL_STUB_MESSAGE pStubMsg,
                                                  unsigned char* pMemory, PFORMAT_STRING pFormat )
 {
+    unsigned char alignment = pFormat[1] + 1;
     DWORD esize = *(const WORD*)(pFormat+2);
 
     TRACE("(%p, %p, %p)\n", pStubMsg, pMemory, pFormat);
@@ -2125,8 +2146,12 @@ void WINAPI NdrConformantVaryingArrayBuf
     /* compute length */
     pFormat = ComputeVariance(pStubMsg, pMemory, pFormat, 0);
 
-    /* conformance + offset + variance + array */
-    pStubMsg->BufferLength += 3*sizeof(DWORD) + pStubMsg->ActualCount*esize;
+    /* conformance + offset + variance */
+    pStubMsg->BufferLength += 3 * sizeof(DWORD);
+
+    ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
+
+    pStubMsg->BufferLength += pStubMsg->ActualCount*esize;
 
     EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat);
 }
@@ -2152,6 +2177,7 @@ unsigned char * WINAPI NdrComplexArrayMa
 {
   ULONG count, def;
   BOOL variance_present;
+  unsigned char alignment;
 
   TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
 
@@ -2162,6 +2188,8 @@ unsigned char * WINAPI NdrComplexArrayMa
       return NULL;
   }
 
+  alignment = pFormat[1] + 1;
+
   def = *(const WORD*)&pFormat[2];
   pFormat += 4;
 
@@ -2182,6 +2210,8 @@ unsigned char * WINAPI NdrComplexArrayMa
     pStubMsg->Buffer += 4;
   }
 
+  ALIGN_POINTER(pStubMsg->Buffer, alignment);
+
   for (count = 0; count < pStubMsg->ActualCount; count++)
     pMemory = ComplexMarshall(pStubMsg, pMemory, pFormat, NULL);
 
@@ -2199,6 +2229,7 @@ unsigned char * WINAPI NdrComplexArrayUn
                                                  unsigned char fMustAlloc)
 {
   ULONG count, esize;
+  unsigned char alignment;
   unsigned char *pMemory;
 
   TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
@@ -2210,6 +2241,8 @@ unsigned char * WINAPI NdrComplexArrayUn
       return NULL;
   }
 
+  alignment = pFormat[1] + 1;
+
   pFormat += 4;
 
   pFormat = ReadConformance(pStubMsg, pFormat);
@@ -2223,6 +2256,8 @@ unsigned char * WINAPI NdrComplexArrayUn
     memset(*ppMemory, 0, pStubMsg->MaxCount * esize);
   }
 
+  ALIGN_POINTER(pStubMsg->Buffer, alignment);
+
   pMemory = *ppMemory;
   for (count = 0; count < pStubMsg->ActualCount; count++)
     pMemory = ComplexUnmarshall(pStubMsg, pMemory, pFormat, NULL, fMustAlloc);
@@ -2238,6 +2273,7 @@ void WINAPI NdrComplexArrayBufferSize(PM
                                       PFORMAT_STRING pFormat)
 {
   ULONG count, def;
+  unsigned char alignment;
   BOOL variance_present;
 
   TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);
@@ -2249,6 +2285,8 @@ void WINAPI NdrComplexArrayBufferSize(PM
       return;
   }
 
+  alignment = pFormat[1] + 1;
+
   def = *(const WORD*)&pFormat[2];
   pFormat += 4;
 
@@ -2263,6 +2301,8 @@ void WINAPI NdrComplexArrayBufferSize(PM
   if (variance_present)
     pStubMsg->BufferLength += 2*sizeof(ULONG);
 
+  ALIGN_LENGTH(pStubMsg->BufferLength, alignment);
+
   for (count=0; count < pStubMsg->ActualCount; count++)
     pMemory = ComplexBufferSize(pStubMsg, pMemory, pFormat, NULL);
 }




More information about the wine-cvs mailing list