- RtlUnicodeStringToCountedOemString improvements:

* Fix zero-sized input string handling, result would be error instead of success and zero output string.
 * If destination string's MaximumLength and Length are equal, it's not an erroneous situation (in fact, a very common situation).
 * Add comments.

svn path=/trunk/; revision=38808
This commit is contained in:
Aleksey Bragin 2009-01-17 07:44:28 +00:00
parent d80bf3ef94
commit f8a4f92088

View file

@ -1492,38 +1492,47 @@ RtlUnicodeStringToCountedOemString(
PAGED_CODE_RTL();
/* Calculate size of the string */
Length = RtlUnicodeStringToCountedOemSize(UniSource);
/* If it's 0 then zero out dest string and return */
if (!Length)
{
RtlZeroMemory(OemDest, sizeof(OEM_STRING));
return STATUS_SUCCESS;
}
/* Check if length is a sane value */
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
/* Store it in dest string */
OemDest->Length = (USHORT)Length;
/* If we're asked to alloc the string - do so */
if (AllocateDestinationString)
{
OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
OemDest->MaximumLength = Length;
if (!OemDest->Buffer) return STATUS_NO_MEMORY;
}
else if (OemDest->Length >= OemDest->MaximumLength)
else if (OemDest->Length > OemDest->MaximumLength)
{
return STATUS_BUFFER_OVERFLOW;
}
/* Do the conversion */
Status = RtlUnicodeToOemN(OemDest->Buffer,
OemDest->Length,
&Index,
UniSource->Buffer,
UniSource->Length);
/* FIXME: Special check needed and return STATUS_UNMAPPABLE_CHARACTER */
/* FIXME: Check if everything mapped correctly and
* return STATUS_UNMAPPABLE_CHARACTER */
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
/* Conversion failed, free dest string and return status code */
RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
OemDest->Buffer = NULL;
return Status;