fixed RegisterWindowMessage()

svn path=/trunk/; revision=9442
This commit is contained in:
Thomas Bluemel 2004-05-19 19:09:20 +00:00
parent 1f14756983
commit 23c42995a1
3 changed files with 68 additions and 71 deletions

View file

@ -7,4 +7,8 @@ NTSTATUS FASTCALL
IntSafeCopyUnicodeString(PUNICODE_STRING Dest, IntSafeCopyUnicodeString(PUNICODE_STRING Dest,
PUNICODE_STRING Source); PUNICODE_STRING Source);
NTSTATUS FASTCALL
IntSafeCopyUnicodeStringTerminateNULL(PUNICODE_STRING Dest,
PUNICODE_STRING Source);
#endif /* ndef _SUBSYS_WIN32K_INCLUDE_CLEANUP_H */ #endif /* ndef _SUBSYS_WIN32K_INCLUDE_CLEANUP_H */

View file

@ -1,4 +1,4 @@
/* $Id: misc.c,v 1.73 2004/05/14 23:57:32 weiden Exp $ /* $Id: misc.c,v 1.74 2004/05/19 19:09:20 weiden Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -1132,3 +1132,51 @@ IntSafeCopyUnicodeString(PUNICODE_STRING Dest,
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
NTSTATUS FASTCALL
IntSafeCopyUnicodeStringTerminateNULL(PUNICODE_STRING Dest,
PUNICODE_STRING Source)
{
NTSTATUS Status;
PWSTR Src;
Status = MmCopyFromCaller(Dest, Source, sizeof(UNICODE_STRING));
if(!NT_SUCCESS(Status))
{
return Status;
}
if(Dest->Length > 0x4000)
{
return STATUS_UNSUCCESSFUL;
}
Src = Dest->Buffer;
Dest->Buffer = NULL;
if(Dest->Length > 0 && Src)
{
Dest->Buffer = ExAllocatePoolWithTag(NonPagedPool, Dest->Length + sizeof(WCHAR), TAG_STRING);
if(!Dest->Buffer)
{
return STATUS_NO_MEMORY;
}
Status = MmCopyFromCaller(Dest->Buffer, Src, Dest->Length);
if(!NT_SUCCESS(Status))
{
ExFreePool(Dest->Buffer);
Dest->Buffer = NULL;
return Status;
}
/* make sure the string is null-terminated */
Src = (PWSTR)((PBYTE)Dest->Buffer + Dest->Length);
*Src = L'\0';
return STATUS_SUCCESS;
}
/* string is empty */
return STATUS_SUCCESS;
}

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: window.c,v 1.233 2004/05/16 19:31:09 navaraf Exp $ /* $Id: window.c,v 1.234 2004/05/19 19:09:20 weiden Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -3572,76 +3572,21 @@ NtUserRealChildWindowFromPoint(DWORD Unknown0,
UINT STDCALL UINT STDCALL
NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe) NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe)
{ {
#if 0 UNICODE_STRING SafeMessageName;
PLIST_ENTRY Current;
PREGISTERED_MESSAGE NewMsg, RegMsg;
UINT Msg = REGISTERED_MESSAGE_MIN;
UNICODE_STRING MessageName;
NTSTATUS Status; NTSTATUS Status;
UINT Ret;
Status = MmCopyFromCaller(&MessageName, MessageNameUnsafe, sizeof(UNICODE_STRING));
if (! NT_SUCCESS(Status)) Status = IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName, MessageNameUnsafe);
{ if(!NT_SUCCESS(Status))
SetLastNtError(Status); {
return 0; SetLastNtError(Status);
} return 0;
}
NewMsg = ExAllocatePoolWithTag(PagedPool,
sizeof(REGISTERED_MESSAGE) + Ret = (UINT)IntAddAtom(SafeMessageName.Buffer);
MessageName.Length,
TAG_WNAM); RtlFreeUnicodeString(&SafeMessageName);
if (NULL == NewMsg) return Ret;
{
SetLastNtError(STATUS_NO_MEMORY);
return 0;
}
Status = MmCopyFromCaller(NewMsg->MessageName, MessageName.Buffer, MessageName.Length);
if (! NT_SUCCESS(Status))
{
ExFreePool(NewMsg);
SetLastNtError(Status);
return 0;
}
NewMsg->MessageName[MessageName.Length / sizeof(WCHAR)] = L'\0';
if (wcslen(NewMsg->MessageName) != MessageName.Length / sizeof(WCHAR))
{
ExFreePool(NewMsg);
SetLastNtError(STATUS_INVALID_PARAMETER);
return 0;
}
Current = RegisteredMessageListHead.Flink;
while (Current != &RegisteredMessageListHead)
{
RegMsg = CONTAINING_RECORD(Current, REGISTERED_MESSAGE, ListEntry);
if (0 == wcscmp(NewMsg->MessageName, RegMsg->MessageName))
{
ExFreePool(NewMsg);
return Msg;
}
Msg++;
Current = Current->Flink;
}
if (REGISTERED_MESSAGE_MAX < Msg)
{
ExFreePool(NewMsg);
SetLastNtError(STATUS_INSUFFICIENT_RESOURCES);
return 0;
}
InsertTailList(&RegisteredMessageListHead, &(NewMsg->ListEntry));
return Msg;
#else
/*
* Notes:
* - There's no need to call MmSafe*, because it should be done in kernel.
* - The passed UNICODE_STRING is expected to be NULL-terminated.
*/
return (UINT)IntAddAtom(MessageNameUnsafe->Buffer);
#endif
} }