Rob Shearman : rpcrt4: Fix NdrConformantStringUnmarshall to use buffer memory if possible.
Alexandre Julliard
julliard at winehq.org
Mon Dec 17 06:42:10 CST 2007
Module: wine
Branch: master
Commit: 259879d1f518056d1eb7fb8f2fde7990ba5ac72d
URL: http://source.winehq.org/git/wine.git/?a=commit;h=259879d1f518056d1eb7fb8f2fde7990ba5ac72d
Author: Rob Shearman <rob at codeweavers.com>
Date: Sat Dec 15 13:57:21 2007 +0000
rpcrt4: Fix NdrConformantStringUnmarshall to use buffer memory if possible.
---
dlls/rpcrt4/ndr_marshall.c | 25 ++++++++++++++++++++++++-
dlls/rpcrt4/tests/ndr_marshall.c | 5 +----
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/dlls/rpcrt4/ndr_marshall.c b/dlls/rpcrt4/ndr_marshall.c
index bd184e2..2de650d 100644
--- a/dlls/rpcrt4/ndr_marshall.c
+++ b/dlls/rpcrt4/ndr_marshall.c
@@ -826,6 +826,20 @@ unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
ReadConformance(pStubMsg, NULL);
ReadVariance(pStubMsg, NULL, pStubMsg->MaxCount);
+ if (pFormat[1] != RPC_FC_STRING_SIZED && (pStubMsg->MaxCount != pStubMsg->ActualCount))
+ {
+ ERR("buffer size %d must equal memory size %ld for non-sized conformant strings\n",
+ pStubMsg->ActualCount, pStubMsg->MaxCount);
+ RpcRaiseException(RPC_S_INVALID_BOUND);
+ return NULL;
+ }
+ if (pStubMsg->Offset)
+ {
+ ERR("conformant strings can't have Offset (%d)\n", pStubMsg->Offset);
+ RpcRaiseException(RPC_S_INVALID_BOUND);
+ return NULL;
+ }
+
if (*pFormat == RPC_FC_C_CSTRING) esize = 1;
else if (*pFormat == RPC_FC_C_WSTRING) esize = 2;
else {
@@ -864,8 +878,17 @@ unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
return NULL;
}
- if (fMustAlloc || !*ppMemory)
+ if (fMustAlloc)
*ppMemory = NdrAllocate(pStubMsg, memsize);
+ else
+ {
+ if (!pStubMsg->IsClient && !*ppMemory && (pStubMsg->MaxCount == pStubMsg->ActualCount))
+ /* if the data in the RPC buffer is big enough, we just point straight
+ * into it */
+ *ppMemory = pStubMsg->Buffer;
+ else if (!*ppMemory)
+ *ppMemory = NdrAllocate(pStubMsg, memsize);
+ }
safe_copy_from_buffer(pStubMsg, *ppMemory, bufsize);
diff --git a/dlls/rpcrt4/tests/ndr_marshall.c b/dlls/rpcrt4/tests/ndr_marshall.c
index ba5243b..d930701 100644
--- a/dlls/rpcrt4/tests/ndr_marshall.c
+++ b/dlls/rpcrt4/tests/ndr_marshall.c
@@ -1207,10 +1207,9 @@ todo_wine {
mem = NULL;
StubMsg.Buffer = StubMsg.BufferStart;
NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
-todo_wine {
ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
-}
+
my_alloc_called = 0;
mem = NULL;
StubMsg.Buffer = StubMsg.BufferStart;
@@ -1224,10 +1223,8 @@ todo_wine {
mem = mem_orig;
StubMsg.Buffer = StubMsg.BufferStart;
NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
-todo_wine {
ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
-}
my_alloc_called = 0;
mem = mem_orig;
More information about the wine-cvs
mailing list