mirror of
https://github.com/reactos/reactos.git
synced 2024-11-02 21:09:15 +00:00
- RtlOemStringToCountedUnicodeString improvements:
* Fix STATUS_BUFFER_OVERFLOW when destination string's MaximumLength and Length are equal. * Add comments. svn path=/trunk/; revision=38809
This commit is contained in:
parent
f8a4f92088
commit
4ca6732fcd
|
@ -1182,29 +1182,35 @@ RtlOemStringToCountedUnicodeString(
|
||||||
|
|
||||||
PAGED_CODE_RTL();
|
PAGED_CODE_RTL();
|
||||||
|
|
||||||
|
/* Calculate size of the string */
|
||||||
Length = RtlOemStringToCountedUnicodeSize(OemSource);
|
Length = RtlOemStringToCountedUnicodeSize(OemSource);
|
||||||
|
|
||||||
|
/* If it's 0 then zero out dest string and return */
|
||||||
if (!Length)
|
if (!Length)
|
||||||
{
|
{
|
||||||
RtlZeroMemory(UniDest, sizeof(UNICODE_STRING));
|
RtlZeroMemory(UniDest, sizeof(UNICODE_STRING));
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check if length is a sane value */
|
||||||
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
||||||
|
|
||||||
|
/* Store it in dest string */
|
||||||
UniDest->Length = (USHORT)Length;
|
UniDest->Length = (USHORT)Length;
|
||||||
|
|
||||||
|
/* If we're asked to alloc the string - do so */
|
||||||
if (AllocateDestinationString)
|
if (AllocateDestinationString)
|
||||||
{
|
{
|
||||||
UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
|
UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
|
||||||
UniDest->MaximumLength = Length;
|
UniDest->MaximumLength = Length;
|
||||||
if (!UniDest->Buffer) return STATUS_NO_MEMORY;
|
if (!UniDest->Buffer) return STATUS_NO_MEMORY;
|
||||||
}
|
}
|
||||||
else if (UniDest->Length >= UniDest->MaximumLength)
|
else if (UniDest->Length > UniDest->MaximumLength)
|
||||||
{
|
{
|
||||||
return STATUS_BUFFER_OVERFLOW;
|
return STATUS_BUFFER_OVERFLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Do the conversion */
|
||||||
Status = RtlOemToUnicodeN(UniDest->Buffer,
|
Status = RtlOemToUnicodeN(UniDest->Buffer,
|
||||||
UniDest->Length,
|
UniDest->Length,
|
||||||
&Index,
|
&Index,
|
||||||
|
@ -1213,6 +1219,7 @@ RtlOemStringToCountedUnicodeString(
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status) && AllocateDestinationString)
|
if (!NT_SUCCESS(Status) && AllocateDestinationString)
|
||||||
{
|
{
|
||||||
|
/* Conversion failed, free dest string and return status code */
|
||||||
RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
|
RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
|
||||||
UniDest->Buffer = NULL;
|
UniDest->Buffer = NULL;
|
||||||
return Status;
|
return Status;
|
||||||
|
|
Loading…
Reference in a new issue