[RTL] - Make sure RtlInitUnicodeString(Ex) don't set odd length. Fixes ntdll:rtlstr winetest.

svn path=/trunk/; revision=54061
This commit is contained in:
Rafal Harabien 2011-10-09 09:55:40 +00:00
parent 34c8ab588c
commit 975d94d909

View file

@ -584,11 +584,12 @@ RtlInitUnicodeString(
IN PCWSTR SourceString)
{
SIZE_T Size;
CONST SIZE_T MaxSize = (MAXUSHORT & ~1) - sizeof(WCHAR); // an even number
if (SourceString)
{
Size = wcslen(SourceString) * sizeof(WCHAR);
if (Size > (MAXUSHORT - sizeof(WCHAR))) Size = MAXUSHORT - sizeof(WCHAR);
if (Size > MaxSize) Size = MaxSize;
DestinationString->Length = (USHORT)Size;
DestinationString->MaximumLength = (USHORT)Size + sizeof(WCHAR);
}
@ -611,11 +612,12 @@ RtlInitUnicodeStringEx(
IN PCWSTR SourceString)
{
SIZE_T Size;
CONST SIZE_T MaxSize = (MAXUSHORT & ~1) - sizeof(WCHAR); // an even number
if (SourceString)
{
Size = wcslen(SourceString) * sizeof(WCHAR);
if (Size > (MAXUSHORT - sizeof(WCHAR))) return STATUS_NAME_TOO_LONG;
if (Size > MaxSize) return STATUS_NAME_TOO_LONG;
DestinationString->Length = (USHORT)Size;
DestinationString->MaximumLength = (USHORT)Size + sizeof(WCHAR);
}