Fixed wrong string length calculation in RtlAppendUnicodeToString().

svn path=/trunk/; revision=2615
This commit is contained in:
Eric Kohl 2002-02-09 23:29:50 +00:00
parent 0fdb820f0b
commit 0ce194ac1a
2 changed files with 235 additions and 294 deletions

View file

@ -1,4 +1,4 @@
/* $Id: unicode.c,v 1.18 2001/03/01 15:30:36 ekohl Exp $ /* $Id: unicode.c,v 1.19 2002/02/09 23:29:50 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -206,27 +206,24 @@ RtlAppendUnicodeStringToString (
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
RtlAppendUnicodeToString ( IN PWSTR Source)
IN OUT PUNICODE_STRING Destination,
IN PWSTR Source
)
{ {
PWCHAR Src; PWCHAR Src;
PWCHAR Dest; PWCHAR Dest;
ULONG i; ULONG i;
ULONG slen; ULONG slen;
slen = wcslen (Source); slen = wcslen(Source) * sizeof(WCHAR);
if (Destination->Length + slen >= Destination->MaximumLength) if (Destination->Length + slen >= Destination->MaximumLength)
return STATUS_BUFFER_TOO_SMALL; return(STATUS_BUFFER_TOO_SMALL);
Src = Source; Src = Source;
Dest = Destination->Buffer + (Destination->Length / sizeof(WCHAR)); Dest = Destination->Buffer + (Destination->Length / sizeof(WCHAR));
for (i = 0; i < slen; i++) for (i = 0; i < (slen / sizeof(WCHAR)); i++)
{ {
*Dest = *Src; *Dest = *Src;
Dest++; Dest++;
@ -234,9 +231,9 @@ RtlAppendUnicodeToString (
} }
*Dest = 0; *Dest = 0;
Destination->Length += (slen * sizeof(WCHAR)); Destination->Length += slen;
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }

View file

@ -1,4 +1,4 @@
/* $Id: unicode.c,v 1.19 2001/11/02 09:10:49 ekohl Exp $ /* $Id: unicode.c,v 1.20 2002/02/09 23:29:12 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -27,7 +27,7 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
WCHAR STDCALL WCHAR STDCALL
RtlAnsiCharToUnicodeChar(CHAR AnsiChar) RtlAnsiCharToUnicodeChar(IN CHAR AnsiChar)
{ {
ULONG Size; ULONG Size;
WCHAR UnicodeChar; WCHAR UnicodeChar;
@ -43,13 +43,12 @@ RtlAnsiCharToUnicodeChar(CHAR AnsiChar)
&AnsiChar, &AnsiChar,
Size); Size);
return UnicodeChar; return(UnicodeChar);
} }
ULONG ULONG STDCALL
STDCALL RtlAnsiStringToUnicodeSize(IN PANSI_STRING AnsiString)
RtlAnsiStringToUnicodeSize(PANSI_STRING AnsiString)
{ {
ULONG Size; ULONG Size;
@ -57,17 +56,14 @@ RtlAnsiStringToUnicodeSize(PANSI_STRING AnsiString)
AnsiString->Buffer, AnsiString->Buffer,
AnsiString->Length); AnsiString->Length);
return Size; return(Size);
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlAnsiStringToUnicodeString(IN OUT PUNICODE_STRING DestinationString,
RtlAnsiStringToUnicodeString ( IN PANSI_STRING SourceString,
PUNICODE_STRING DestinationString, IN BOOLEAN AllocateDestinationString)
PANSI_STRING SourceString,
BOOLEAN AllocateDestinationString
)
{ {
NTSTATUS Status; NTSTATUS Status;
ULONG Length; ULONG Length;
@ -118,12 +114,9 @@ RtlAnsiStringToUnicodeString (
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlAppendAsciizToString(IN OUT PSTRING Destination,
RtlAppendAsciizToString ( IN PCSZ Source)
IN OUT PSTRING Destination,
IN PCSZ Source
)
{ {
ULONG Length; ULONG Length;
PCHAR Ptr; PCHAR Ptr;
@ -148,20 +141,17 @@ RtlAppendAsciizToString (
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlAppendStringToString(IN OUT PSTRING Destination,
RtlAppendStringToString ( IN PSTRING Source)
PSTRING Destination,
PSTRING Source
)
{ {
PCHAR Ptr; PCHAR Ptr;
if (Source->Length == 0) if (Source->Length == 0)
return STATUS_SUCCESS; return(STATUS_SUCCESS);
if (Destination->Length + Source->Length >= Destination->MaximumLength) if (Destination->Length + Source->Length >= Destination->MaximumLength)
return STATUS_BUFFER_TOO_SMALL; return(STATUS_BUFFER_TOO_SMALL);
Ptr = Destination->Buffer + Destination->Length; Ptr = Destination->Buffer + Destination->Length;
memmove(Ptr, memmove(Ptr,
@ -172,16 +162,13 @@ RtlAppendStringToString (
Destination->Length += Source->Length; Destination->Length += Source->Length;
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlAppendUnicodeStringToString(IN OUT PUNICODE_STRING Destination,
RtlAppendUnicodeStringToString ( IN PUNICODE_STRING Source)
IN OUT PUNICODE_STRING Destination,
IN PUNICODE_STRING Source
)
{ {
PWCHAR Src, Dest; PWCHAR Src, Dest;
ULONG i; ULONG i;
@ -205,27 +192,24 @@ RtlAppendUnicodeStringToString (
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
RtlAppendUnicodeToString ( IN PWSTR Source)
IN OUT PUNICODE_STRING Destination,
IN PWSTR Source
)
{ {
PWCHAR Src; PWCHAR Src;
PWCHAR Dest; PWCHAR Dest;
ULONG i; ULONG i;
ULONG slen; ULONG slen;
slen = wcslen (Source); slen = wcslen(Source) * sizeof(WCHAR);
if (Destination->Length + slen >= Destination->MaximumLength) if (Destination->Length + slen >= Destination->MaximumLength)
return STATUS_BUFFER_TOO_SMALL; return(STATUS_BUFFER_TOO_SMALL);
Src = Source; Src = Source;
Dest = Destination->Buffer + (Destination->Length / sizeof(WCHAR)); Dest = Destination->Buffer + (Destination->Length / sizeof(WCHAR));
for (i = 0; i < slen; i++) for (i = 0; i < (slen / sizeof(WCHAR)); i++)
{ {
*Dest = *Src; *Dest = *Src;
Dest++; Dest++;
@ -233,15 +217,16 @@ RtlAppendUnicodeToString (
} }
*Dest = 0; *Dest = 0;
Destination->Length += (slen * sizeof(WCHAR)); Destination->Length += slen;
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlCharToInteger(IN PCSZ String,
RtlCharToInteger(IN PCSZ String, IN ULONG Base, IN OUT PULONG Value) IN ULONG Base,
IN OUT PULONG Value)
{ {
ULONG Val; ULONG Val;
@ -263,7 +248,7 @@ RtlCharToInteger(IN PCSZ String, IN ULONG Base, IN OUT PULONG Value)
} }
if (!isxdigit (*String)) if (!isxdigit (*String))
return STATUS_INVALID_PARAMETER; return(STATUS_INVALID_PARAMETER);
while (isxdigit (*String) && while (isxdigit (*String) &&
(Val = isdigit (*String) ? * String - '0' : (islower (*String) (Val = isdigit (*String) ? * String - '0' : (islower (*String)
@ -273,17 +258,14 @@ RtlCharToInteger(IN PCSZ String, IN ULONG Base, IN OUT PULONG Value)
String++; String++;
} }
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
LONG LONG STDCALL
STDCALL RtlCompareString(IN PSTRING String1,
RtlCompareString (
IN PSTRING String1,
IN PSTRING String2, IN PSTRING String2,
IN BOOLEAN CaseInsensitive IN BOOLEAN CaseInsensitive)
)
{ {
ULONG len1, len2; ULONG len1, len2;
PCHAR s1, s2; PCHAR s1, s2;
@ -325,13 +307,10 @@ RtlCompareString (
} }
LONG LONG STDCALL
STDCALL RtlCompareUnicodeString(IN PUNICODE_STRING String1,
RtlCompareUnicodeString (
IN PUNICODE_STRING String1,
IN PUNICODE_STRING String2, IN PUNICODE_STRING String2,
IN BOOLEAN CaseInsensitive IN BOOLEAN CaseInsensitive)
)
{ {
ULONG len1, len2; ULONG len1, len2;
PWCHAR s1, s2; PWCHAR s1, s2;
@ -373,12 +352,9 @@ RtlCompareUnicodeString (
} }
VOID VOID STDCALL
STDCALL RtlCopyString(IN OUT PSTRING DestinationString,
RtlCopyString ( IN PSTRING SourceString)
IN OUT PSTRING DestinationString,
IN PSTRING SourceString
)
{ {
ULONG copylen, i; ULONG copylen, i;
PCHAR Src, Dest; PCHAR Src, Dest;
@ -406,12 +382,9 @@ RtlCopyString (
} }
VOID VOID STDCALL
STDCALL RtlCopyUnicodeString(IN OUT PUNICODE_STRING DestinationString,
RtlCopyUnicodeString ( IN PUNICODE_STRING SourceString)
IN OUT PUNICODE_STRING DestinationString,
IN PUNICODE_STRING SourceString
)
{ {
ULONG copylen, i; ULONG copylen, i;
PWCHAR Src, Dest; PWCHAR Src, Dest;
@ -439,12 +412,9 @@ RtlCopyUnicodeString (
} }
BOOLEAN BOOLEAN STDCALL
STDCALL RtlCreateUnicodeString(IN OUT PUNICODE_STRING Destination,
RtlCreateUnicodeString ( IN PWSTR Source)
IN OUT PUNICODE_STRING Destination,
IN PWSTR Source
)
{ {
ULONG Length; ULONG Length;
@ -467,12 +437,9 @@ RtlCreateUnicodeString (
} }
BOOLEAN BOOLEAN STDCALL
STDCALL RtlCreateUnicodeStringFromAsciiz(IN OUT PUNICODE_STRING Destination,
RtlCreateUnicodeStringFromAsciiz ( IN PCSZ Source)
IN OUT PUNICODE_STRING Destination,
IN PCSZ Source
)
{ {
ANSI_STRING AnsiString; ANSI_STRING AnsiString;
NTSTATUS Status; NTSTATUS Status;
@ -484,7 +451,7 @@ RtlCreateUnicodeStringFromAsciiz (
&AnsiString, &AnsiString,
TRUE); TRUE);
return NT_SUCCESS(Status); return(NT_SUCCESS(Status));
} }
@ -540,13 +507,10 @@ RtlDowncaseUnicodeString (IN OUT PUNICODE_STRING DestinationString,
} }
BOOLEAN BOOLEAN STDCALL
STDCALL RtlEqualString(IN PSTRING String1,
RtlEqualString (
IN PSTRING String1,
IN PSTRING String2, IN PSTRING String2,
IN BOOLEAN CaseInsensitive IN BOOLEAN CaseInsensitive)
)
{ {
unsigned long s1l=String1->Length; unsigned long s1l=String1->Length;
unsigned long s2l=String2->Length; unsigned long s2l=String2->Length;
@ -585,13 +549,10 @@ RtlEqualString (
} }
BOOLEAN BOOLEAN STDCALL
STDCALL RtlEqualUnicodeString(IN PUNICODE_STRING String1,
RtlEqualUnicodeString (
IN PUNICODE_STRING String1,
IN PUNICODE_STRING String2, IN PUNICODE_STRING String2,
IN BOOLEAN CaseInsensitive IN BOOLEAN CaseInsensitive)
)
{ {
unsigned long s1l = String1->Length / sizeof(WCHAR); unsigned long s1l = String1->Length / sizeof(WCHAR);
unsigned long s2l = String2->Length / sizeof(WCHAR); unsigned long s2l = String2->Length / sizeof(WCHAR);
@ -629,11 +590,8 @@ RtlEqualUnicodeString (
} }
VOID VOID STDCALL
STDCALL RtlFreeAnsiString(IN PANSI_STRING AnsiString)
RtlFreeAnsiString (
IN PANSI_STRING AnsiString
)
{ {
if (AnsiString->Buffer == NULL) if (AnsiString->Buffer == NULL)
return; return;
@ -646,11 +604,8 @@ RtlFreeAnsiString (
} }
VOID VOID STDCALL
STDCALL RtlFreeOemString(IN POEM_STRING OemString)
RtlFreeOemString (
IN POEM_STRING OemString
)
{ {
if (OemString->Buffer == NULL) if (OemString->Buffer == NULL)
return; return;
@ -663,11 +618,8 @@ RtlFreeOemString (
} }
VOID VOID STDCALL
STDCALL RtlFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
RtlFreeUnicodeString (
IN PUNICODE_STRING UnicodeString
)
{ {
if (UnicodeString->Buffer == NULL) if (UnicodeString->Buffer == NULL)
return; return;
@ -680,12 +632,9 @@ RtlFreeUnicodeString (
} }
VOID VOID STDCALL
STDCALL RtlInitAnsiString(IN OUT PANSI_STRING DestinationString,
RtlInitAnsiString ( IN PCSZ SourceString)
IN OUT PANSI_STRING DestinationString,
IN PCSZ SourceString
)
{ {
ULONG DestSize; ULONG DestSize;
@ -705,10 +654,8 @@ RtlInitAnsiString (
VOID STDCALL VOID STDCALL
RtlInitString ( RtlInitString(IN OUT PSTRING DestinationString,
IN OUT PSTRING DestinationString, IN PCSZ SourceString)
IN PCSZ SourceString
)
{ {
ULONG DestSize; ULONG DestSize;
@ -728,10 +675,8 @@ RtlInitString (
VOID STDCALL VOID STDCALL
RtlInitUnicodeString ( RtlInitUnicodeString(IN OUT PUNICODE_STRING DestinationString,
IN OUT PUNICODE_STRING DestinationString, IN PCWSTR SourceString)
IN PCWSTR SourceString
)
{ {
ULONG DestSize; ULONG DestSize;
@ -755,12 +700,10 @@ RtlInitUnicodeString (
NTSTATUS STDCALL NTSTATUS STDCALL
RtlIntegerToChar ( RtlIntegerToChar(IN ULONG Value,
IN ULONG Value,
IN ULONG Base, IN ULONG Base,
IN ULONG Length, IN ULONG Length,
IN OUT PCHAR String IN OUT PCHAR String)
)
{ {
ULONG Radix; ULONG Radix;
CHAR temp[33]; CHAR temp[33];
@ -1428,18 +1371,18 @@ RtlUpcaseUnicodeStringToCountedOemString(IN OUT POEM_STRING DestinationString,
Length = SourceString->Length / sizeof(WCHAR) + 1; Length = SourceString->Length / sizeof(WCHAR) + 1;
if (Length > 0x0000FFFF) if (Length > 0x0000FFFF)
return STATUS_INVALID_PARAMETER_2; return(STATUS_INVALID_PARAMETER_2);
DestinationString->Length = (WORD)(Length - 1); DestinationString->Length = (WORD)(Length - 1);
if (AllocateDestinationString == TRUE) if (AllocateDestinationString == TRUE)
{ {
DestinationString->Buffer = ExAllocatePoolWithTag (NonPagedPool, DestinationString->Buffer =
ExAllocatePoolWithTag(NonPagedPool,
Length, Length,
TAG_OSTR); TAG_OSTR);
if (DestinationString->Buffer == NULL) if (DestinationString->Buffer == NULL)
return STATUS_NO_MEMORY; return(STATUS_NO_MEMORY);
RtlZeroMemory(DestinationString->Buffer, RtlZeroMemory(DestinationString->Buffer,
Length); Length);
@ -1450,7 +1393,7 @@ RtlUpcaseUnicodeStringToCountedOemString(IN OUT POEM_STRING DestinationString,
if (Length > DestinationString->MaximumLength) if (Length > DestinationString->MaximumLength)
{ {
if (DestinationString->MaximumLength == 0) if (DestinationString->MaximumLength == 0)
return STATUS_BUFFER_OVERFLOW; return(STATUS_BUFFER_OVERFLOW);
DestinationString->Length = DestinationString->Length =
DestinationString->MaximumLength - 1; DestinationString->MaximumLength - 1;
} }
@ -1465,13 +1408,12 @@ RtlUpcaseUnicodeStringToCountedOemString(IN OUT POEM_STRING DestinationString,
{ {
if (AllocateDestinationString) if (AllocateDestinationString)
ExFreePool(DestinationString->Buffer); ExFreePool(DestinationString->Buffer);
return(Status);
return Status;
} }
DestinationString->Buffer[Size] = 0; DestinationString->Buffer[Size] = 0;
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
@ -1484,22 +1426,24 @@ RtlUpcaseUnicodeStringToOemString(IN OUT POEM_STRING DestinationString,
ULONG Length; ULONG Length;
if (NlsMbOemCodePageTag == TRUE) if (NlsMbOemCodePageTag == TRUE)
Length = RtlUnicodeStringToAnsiSize (SourceString); Length = RtlUnicodeStringToOemSize(SourceString);
else else
Length = SourceString->Length / sizeof(WCHAR); Length = SourceString->Length / sizeof(WCHAR);
if (AllocateDestinationString == TRUE) if (AllocateDestinationString == TRUE)
{ {
DestinationString->MaximumLength = Length + sizeof(CHAR); DestinationString->MaximumLength = Length + sizeof(CHAR);
DestinationString->Buffer = ExAllocatePoolWithTag (NonPagedPool, DestinationString->Buffer =
DestinationString->MaximumLength, TAG_OSTR); ExAllocatePoolWithTag(NonPagedPool,
DestinationString->MaximumLength,
TAG_OSTR);
if (DestinationString->Buffer == NULL) if (DestinationString->Buffer == NULL)
return STATUS_NO_MEMORY; return(STATUS_NO_MEMORY);
} }
else else
{ {
if (Length >= DestinationString->MaximumLength) if (Length >= DestinationString->MaximumLength)
return STATUS_BUFFER_TOO_SMALL; return(STATUS_BUFFER_TOO_SMALL);
} }
DestinationString->Length = Length; DestinationString->Length = Length;
@ -1515,12 +1459,12 @@ RtlUpcaseUnicodeStringToOemString(IN OUT POEM_STRING DestinationString,
{ {
if (AllocateDestinationString) if (AllocateDestinationString)
ExFreePool(DestinationString->Buffer); ExFreePool(DestinationString->Buffer);
return Status; return(Status);
} }
DestinationString->Buffer[Length] = 0; DestinationString->Buffer[Length] = 0;
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
@ -1595,7 +1539,7 @@ RtlxAnsiStringToUnicodeSize(IN PANSI_STRING AnsiString)
ULONG STDCALL ULONG STDCALL
RtlxOemStringToUnicodeSize(IN POEM_STRING OemString) RtlxOemStringToUnicodeSize(IN POEM_STRING OemString)
{ {
return(RtlAnsiStringToUnicodeSize((PANSI_STRING)OemString)); return(RtlOemStringToUnicodeSize((PANSI_STRING)OemString));
} }
@ -1609,7 +1553,7 @@ RtlxUnicodeStringToAnsiSize(IN PUNICODE_STRING UnicodeString)
ULONG STDCALL ULONG STDCALL
RtlxUnicodeStringToOemSize(IN PUNICODE_STRING UnicodeString) RtlxUnicodeStringToOemSize(IN PUNICODE_STRING UnicodeString)
{ {
return(RtlUnicodeStringToAnsiSize(UnicodeString)); return(RtlUnicodeStringToOemSize(UnicodeString));
} }
/* EOF */ /* EOF */