fixed converting the unicode string back to ansi in
GetNamedPipeHandleStateA, also check if memory allocation failed
(reported by M Bealby in bug #1110)
Modified: trunk/reactos/lib/kernel32/file/npipe.c
_____
Modified: trunk/reactos/lib/kernel32/file/npipe.c
--- trunk/reactos/lib/kernel32/file/npipe.c 2005-12-11 19:30:07 UTC
(rev 20076)
+++ trunk/reactos/lib/kernel32/file/npipe.c 2005-12-11 19:36:43 UTC
(rev 20077)
@@ -905,15 +905,19 @@
LPSTR lpUserName,
DWORD nMaxUserNameSize)
{
- UNICODE_STRING UserNameW;
+ UNICODE_STRING UserNameW = {0};
ANSI_STRING UserNameA;
BOOL Ret;
if(lpUserName != NULL)
{
- UserNameW.Length = 0;
UserNameW.MaximumLength = nMaxUserNameSize * sizeof(WCHAR);
- UserNameW.Buffer = HeapAlloc(GetCurrentProcess(), 0,
UserNameW.MaximumLength);
+ UserNameW.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0,
UserNameW.MaximumLength);
+ if (UserNameW.Buffer == NULL)
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
UserNameA.Buffer = lpUserName;
UserNameA.Length = 0;
@@ -930,7 +934,10 @@
if(Ret && lpUserName != NULL)
{
- NTSTATUS Status = RtlUnicodeStringToAnsiString(&UserNameA,
&UserNameW, FALSE);
+ NTSTATUS Status;
+
+ RtlInitUnicodeString(&UserNameW, UserNameW.Buffer);
+ Status = RtlUnicodeStringToAnsiString(&UserNameA, &UserNameW,
FALSE);
if(!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
@@ -940,7 +947,7 @@
if(UserNameW.Buffer != NULL)
{
- HeapFree(GetCurrentProcess(), 0, UserNameW.Buffer);
+ RtlFreeHeap(RtlGetProcessHeap(), 0, UserNameW.Buffer);
}
return Ret;
Show replies by date