diff --git a/reactos/subsys/win32k/include/cleanup.h b/reactos/subsys/win32k/include/cleanup.h index bdc5d3a078d..6ceb9166f8b 100644 --- a/reactos/subsys/win32k/include/cleanup.h +++ b/reactos/subsys/win32k/include/cleanup.h @@ -7,4 +7,8 @@ NTSTATUS FASTCALL IntSafeCopyUnicodeString(PUNICODE_STRING Dest, PUNICODE_STRING Source); +NTSTATUS FASTCALL +IntSafeCopyUnicodeStringTerminateNULL(PUNICODE_STRING Dest, + PUNICODE_STRING Source); + #endif /* ndef _SUBSYS_WIN32K_INCLUDE_CLEANUP_H */ diff --git a/reactos/subsys/win32k/ntuser/misc.c b/reactos/subsys/win32k/ntuser/misc.c index 426b302528d..ac0a1823b51 100644 --- a/reactos/subsys/win32k/ntuser/misc.c +++ b/reactos/subsys/win32k/ntuser/misc.c @@ -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 * PROJECT: ReactOS kernel @@ -1132,3 +1132,51 @@ IntSafeCopyUnicodeString(PUNICODE_STRING Dest, 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; +} + diff --git a/reactos/subsys/win32k/ntuser/window.c b/reactos/subsys/win32k/ntuser/window.c index aa522f932e5..dccc1df6414 100644 --- a/reactos/subsys/win32k/ntuser/window.c +++ b/reactos/subsys/win32k/ntuser/window.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * 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 * PROJECT: ReactOS kernel @@ -3572,76 +3572,21 @@ NtUserRealChildWindowFromPoint(DWORD Unknown0, UINT STDCALL NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe) { -#if 0 - PLIST_ENTRY Current; - PREGISTERED_MESSAGE NewMsg, RegMsg; - UINT Msg = REGISTERED_MESSAGE_MIN; - UNICODE_STRING MessageName; + UNICODE_STRING SafeMessageName; NTSTATUS Status; - - Status = MmCopyFromCaller(&MessageName, MessageNameUnsafe, sizeof(UNICODE_STRING)); - if (! NT_SUCCESS(Status)) - { - SetLastNtError(Status); - return 0; - } - - NewMsg = ExAllocatePoolWithTag(PagedPool, - sizeof(REGISTERED_MESSAGE) + - MessageName.Length, - TAG_WNAM); - if (NULL == NewMsg) - { - 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 + UINT Ret; + + Status = IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName, MessageNameUnsafe); + if(!NT_SUCCESS(Status)) + { + SetLastNtError(Status); + return 0; + } + + Ret = (UINT)IntAddAtom(SafeMessageName.Buffer); + + RtlFreeUnicodeString(&SafeMessageName); + return Ret; }