rpcrt4: Clean up handling of enum16 types.

This commit is contained in:
Alexandre Julliard 2010-04-07 13:04:32 +02:00
parent 4f62b09071
commit cf50aa91f6
1 changed files with 21 additions and 14 deletions

View File

@ -2822,12 +2822,15 @@ static unsigned char * ComplexMarshall(PMIDL_STUB_MESSAGE pStubMsg,
pMemory += 2; pMemory += 2;
break; break;
case RPC_FC_ENUM16: case RPC_FC_ENUM16:
{
USHORT val = *(DWORD *)pMemory;
TRACE("enum16=%d <= %p\n", *(DWORD*)pMemory, pMemory); TRACE("enum16=%d <= %p\n", *(DWORD*)pMemory, pMemory);
if (32767 < *(DWORD*)pMemory) if (32767 < *(DWORD*)pMemory)
RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE); RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
safe_copy_to_buffer(pStubMsg, pMemory, 2); safe_copy_to_buffer(pStubMsg, &val, 2);
pMemory += 4; pMemory += 4;
break; break;
}
case RPC_FC_LONG: case RPC_FC_LONG:
case RPC_FC_ULONG: case RPC_FC_ULONG:
case RPC_FC_ENUM32: case RPC_FC_ENUM32:
@ -2969,13 +2972,16 @@ static unsigned char * ComplexUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,
pMemory += 2; pMemory += 2;
break; break;
case RPC_FC_ENUM16: case RPC_FC_ENUM16:
safe_copy_from_buffer(pStubMsg, pMemory, 2); {
*(DWORD*)pMemory &= 0xffff; WORD val;
safe_copy_from_buffer(pStubMsg, &val, 2);
*(DWORD*)pMemory = val;
TRACE("enum16=%d => %p\n", *(DWORD*)pMemory, pMemory); TRACE("enum16=%d => %p\n", *(DWORD*)pMemory, pMemory);
if (32767 < *(DWORD*)pMemory) if (32767 < *(DWORD*)pMemory)
RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE); RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
pMemory += 4; pMemory += 4;
break; break;
}
case RPC_FC_LONG: case RPC_FC_LONG:
case RPC_FC_ULONG: case RPC_FC_ULONG:
case RPC_FC_ENUM32: case RPC_FC_ENUM32:
@ -6544,16 +6550,16 @@ static unsigned char *WINAPI NdrBaseTypeMarshall(
TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory)); TRACE("value: %s\n", wine_dbgstr_longlong(*(ULONGLONG*)pMemory));
break; break;
case RPC_FC_ENUM16: case RPC_FC_ENUM16:
{
USHORT val = *(UINT *)pMemory;
/* only 16-bits on the wire, so do a sanity check */ /* only 16-bits on the wire, so do a sanity check */
if (*(UINT *)pMemory > SHRT_MAX) if (*(UINT *)pMemory > SHRT_MAX)
RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE); RpcRaiseException(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
align_pointer_clear(&pStubMsg->Buffer, sizeof(USHORT)); align_pointer_clear(&pStubMsg->Buffer, sizeof(USHORT));
if (pStubMsg->Buffer + sizeof(USHORT) > (unsigned char *)pStubMsg->RpcMsg->Buffer + pStubMsg->BufferLength) safe_copy_to_buffer(pStubMsg, &val, sizeof(val));
RpcRaiseException(RPC_X_BAD_STUB_DATA);
*(USHORT *)pStubMsg->Buffer = *(UINT *)pMemory;
pStubMsg->Buffer += sizeof(USHORT);
TRACE("value: 0x%04x\n", *(UINT *)pMemory); TRACE("value: 0x%04x\n", *(UINT *)pMemory);
break; break;
}
case RPC_FC_IGNORE: case RPC_FC_IGNORE:
break; break;
default: default:
@ -6575,7 +6581,7 @@ static unsigned char *WINAPI NdrBaseTypeUnmarshall(
{ {
TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false"); TRACE("pStubMsg: %p, ppMemory: %p, type: 0x%02x, fMustAlloc: %s\n", pStubMsg, ppMemory, *pFormat, fMustAlloc ? "true" : "false");
#define BASE_TYPE_UNMARSHALL(type) \ #define BASE_TYPE_UNMARSHALL(type) do { \
align_pointer(&pStubMsg->Buffer, sizeof(type)); \ align_pointer(&pStubMsg->Buffer, sizeof(type)); \
if (!fMustAlloc && !pStubMsg->IsClient && !*ppMemory) \ if (!fMustAlloc && !pStubMsg->IsClient && !*ppMemory) \
{ \ { \
@ -6589,7 +6595,8 @@ static unsigned char *WINAPI NdrBaseTypeUnmarshall(
*ppMemory = NdrAllocate(pStubMsg, sizeof(type)); \ *ppMemory = NdrAllocate(pStubMsg, sizeof(type)); \
TRACE("*ppMemory: %p\n", *ppMemory); \ TRACE("*ppMemory: %p\n", *ppMemory); \
safe_copy_from_buffer(pStubMsg, *ppMemory, sizeof(type)); \ safe_copy_from_buffer(pStubMsg, *ppMemory, sizeof(type)); \
} } \
} while (0)
switch(*pFormat) switch(*pFormat)
{ {
@ -6626,19 +6633,19 @@ static unsigned char *WINAPI NdrBaseTypeUnmarshall(
TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory)); TRACE("value: %s\n", wine_dbgstr_longlong(**(ULONGLONG **)ppMemory));
break; break;
case RPC_FC_ENUM16: case RPC_FC_ENUM16:
{
USHORT val;
align_pointer(&pStubMsg->Buffer, sizeof(USHORT)); align_pointer(&pStubMsg->Buffer, sizeof(USHORT));
if (!fMustAlloc && !*ppMemory) if (!fMustAlloc && !*ppMemory)
fMustAlloc = TRUE; fMustAlloc = TRUE;
if (fMustAlloc) if (fMustAlloc)
*ppMemory = NdrAllocate(pStubMsg, sizeof(UINT)); *ppMemory = NdrAllocate(pStubMsg, sizeof(UINT));
if (pStubMsg->Buffer + sizeof(USHORT) > pStubMsg->BufferEnd) safe_copy_from_buffer(pStubMsg, &val, sizeof(USHORT));
RpcRaiseException(RPC_X_BAD_STUB_DATA);
TRACE("*ppMemory: %p\n", *ppMemory);
/* 16-bits on the wire, but int in memory */ /* 16-bits on the wire, but int in memory */
**(UINT **)ppMemory = *(USHORT *)pStubMsg->Buffer; **(UINT **)ppMemory = val;
pStubMsg->Buffer += sizeof(USHORT);
TRACE("value: 0x%08x\n", **(UINT **)ppMemory); TRACE("value: 0x%08x\n", **(UINT **)ppMemory);
break; break;
}
case RPC_FC_IGNORE: case RPC_FC_IGNORE:
break; break;
default: default: