From bdb2981529a3a91a5bda8f1c47ae89d69dd3f700 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sat, 7 Jun 2003 10:35:27 +0000 Subject: [PATCH] Fixed minor bugs in RtlConvertSidToUnicodeString(). svn path=/trunk/; revision=4862 --- reactos/lib/ntdll/rtl/sid.c | 116 ++++++++++++++++++------------------ reactos/ntoskrnl/se/sid.c | 4 +- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/reactos/lib/ntdll/rtl/sid.c b/reactos/lib/ntdll/rtl/sid.c index 322c5fd120b..6987e9c8f6e 100644 --- a/reactos/lib/ntdll/rtl/sid.c +++ b/reactos/lib/ntdll/rtl/sid.c @@ -1,4 +1,4 @@ -/* $Id: sid.c,v 1.6 2002/09/08 10:23:06 chorns Exp $ +/* $Id: sid.c,v 1.7 2003/06/07 10:35:27 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -243,69 +243,69 @@ RtlConvertSidToUnicodeString(PUNICODE_STRING String, PSID Sid, BOOLEAN AllocateBuffer) { - WCHAR Buffer[256]; - PWSTR wcs; - ULONG Length; - BYTE i; + WCHAR Buffer[256]; + PWSTR wcs; + ULONG Length; + ULONG i; - if (RtlValidSid (Sid) == FALSE) - return STATUS_INVALID_SID; + if (RtlValidSid (Sid) == FALSE) + return STATUS_INVALID_SID; - wcs = Buffer; - wcs += swprintf (wcs, L"S-%u-", Sid->Revision); - if (!Sid->IdentifierAuthority.Value[0] && - !Sid->IdentifierAuthority.Value[1]) - { - wcs += swprintf (wcs, - L"%u", - (DWORD)Sid->IdentifierAuthority.Value[2] << 24 | - (DWORD)Sid->IdentifierAuthority.Value[3] << 16 | - (DWORD)Sid->IdentifierAuthority.Value[4] << 8 | - (DWORD)Sid->IdentifierAuthority.Value[5]); - } - else - { - wcs += swprintf (wcs, - L"0x%02hx%02hx%02hx%02hx%02hx%02hx", - Sid->IdentifierAuthority.Value[0], - Sid->IdentifierAuthority.Value[1], - Sid->IdentifierAuthority.Value[2], - Sid->IdentifierAuthority.Value[3], - Sid->IdentifierAuthority.Value[4], - Sid->IdentifierAuthority.Value[5]); - } + wcs = Buffer; + wcs += swprintf (wcs, L"S-%u-", Sid->Revision); + if (Sid->IdentifierAuthority.Value[0] == 0 && + Sid->IdentifierAuthority.Value[1] == 0) + { + wcs += swprintf (wcs, + L"%lu", + (ULONG)Sid->IdentifierAuthority.Value[2] << 24 | + (ULONG)Sid->IdentifierAuthority.Value[3] << 16 | + (ULONG)Sid->IdentifierAuthority.Value[4] << 8 | + (ULONG)Sid->IdentifierAuthority.Value[5]); + } + else + { + wcs += swprintf (wcs, + L"0x%02hx%02hx%02hx%02hx%02hx%02hx", + Sid->IdentifierAuthority.Value[0], + Sid->IdentifierAuthority.Value[1], + Sid->IdentifierAuthority.Value[2], + Sid->IdentifierAuthority.Value[3], + Sid->IdentifierAuthority.Value[4], + Sid->IdentifierAuthority.Value[5]); + } - for (i = 0; i < Sid->SubAuthorityCount; i++) - { - wcs += swprintf (wcs, - L"-%u", - Sid->SubAuthority[0]); - } + for (i = 0; i < Sid->SubAuthorityCount; i++) + { + wcs += swprintf (wcs, + L"-%u", + Sid->SubAuthority[i]); + } - Length = (wcs - Buffer) * sizeof(WCHAR); - if(AllocateBuffer) - { - String->Buffer = RtlAllocateHeap (RtlGetProcessHeap (), - 0, - Length + sizeof(WCHAR)); - if (String->Buffer == NULL) - return STATUS_NO_MEMORY; - String->MaximumLength = Length + sizeof(WCHAR); - } - else - { - if (Length > String->MaximumLength) - return STATUS_BUFFER_TOO_SMALL; - } + Length = (wcs - Buffer) * sizeof(WCHAR); + if (AllocateBuffer) + { + String->Buffer = RtlAllocateHeap (RtlGetProcessHeap (), + 0, + Length + sizeof(WCHAR)); + if (String->Buffer == NULL) + return STATUS_NO_MEMORY; + String->MaximumLength = Length + sizeof(WCHAR); + } + else + { + if (Length > String->MaximumLength) + return STATUS_BUFFER_TOO_SMALL; + } - String->Length = Length; - memmove (String->Buffer, - Buffer, - Length); - if (Length < String->MaximumLength) - String->Buffer[Length] = 0; + String->Length = Length; + RtlCopyMemory (String->Buffer, + Buffer, + Length); + if (Length < String->MaximumLength) + String->Buffer[Length / sizeof(WCHAR)] = 0; - return STATUS_SUCCESS; + return STATUS_SUCCESS; } /* EOF */ diff --git a/reactos/ntoskrnl/se/sid.c b/reactos/ntoskrnl/se/sid.c index 97c4777f1c8..6a7a9ec63f8 100644 --- a/reactos/ntoskrnl/se/sid.c +++ b/reactos/ntoskrnl/se/sid.c @@ -1,4 +1,4 @@ -/* $Id: sid.c,v 1.12 2002/09/08 10:23:43 chorns Exp $ +/* $Id: sid.c,v 1.13 2003/06/07 10:34:47 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -661,7 +661,7 @@ RtlConvertSidToUnicodeString(PUNICODE_STRING String, Buffer, Length); if (Length < String->MaximumLength) - String->Buffer[Length] = 0; + String->Buffer[Length/sizeof(WCHAR)] = 0; return STATUS_SUCCESS; }