Commit 259879d1 authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

rpcrt4: Fix NdrConformantStringUnmarshall to use buffer memory if possible.

parent b300189c
...@@ -826,6 +826,20 @@ unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg ...@@ -826,6 +826,20 @@ unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
ReadConformance(pStubMsg, NULL); ReadConformance(pStubMsg, NULL);
ReadVariance(pStubMsg, NULL, pStubMsg->MaxCount); 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; if (*pFormat == RPC_FC_C_CSTRING) esize = 1;
else if (*pFormat == RPC_FC_C_WSTRING) esize = 2; else if (*pFormat == RPC_FC_C_WSTRING) esize = 2;
else { else {
...@@ -864,8 +878,17 @@ unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg ...@@ -864,8 +878,17 @@ unsigned char *WINAPI NdrConformantStringUnmarshall( PMIDL_STUB_MESSAGE pStubMsg
return NULL; 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); *ppMemory = NdrAllocate(pStubMsg, memsize);
}
safe_copy_from_buffer(pStubMsg, *ppMemory, bufsize); safe_copy_from_buffer(pStubMsg, *ppMemory, bufsize);
......
...@@ -1207,10 +1207,9 @@ todo_wine { ...@@ -1207,10 +1207,9 @@ todo_wine {
mem = NULL; mem = NULL;
StubMsg.Buffer = StubMsg.BufferStart; StubMsg.Buffer = StubMsg.BufferStart;
NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0); NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
todo_wine {
ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n"); ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called); ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
}
my_alloc_called = 0; my_alloc_called = 0;
mem = NULL; mem = NULL;
StubMsg.Buffer = StubMsg.BufferStart; StubMsg.Buffer = StubMsg.BufferStart;
...@@ -1224,10 +1223,8 @@ todo_wine { ...@@ -1224,10 +1223,8 @@ todo_wine {
mem = mem_orig; mem = mem_orig;
StubMsg.Buffer = StubMsg.BufferStart; StubMsg.Buffer = StubMsg.BufferStart;
NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0); NdrPointerUnmarshall( &StubMsg, &mem, fmtstr_conf_str, 0);
todo_wine {
ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n"); ok(mem == StubMsg.BufferStart + 12, "mem not pointing at buffer\n");
ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called); ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
}
my_alloc_called = 0; my_alloc_called = 0;
mem = mem_orig; mem = mem_orig;
......
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