From 83a2899311c688b66f0c75f434d2b88b603d413c Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Fri, 6 May 2005 00:07:05 +0000 Subject: [PATCH] don't leak the registry path string after initializing a driver svn path=/trunk/; revision=15028 --- reactos/drivers/video/videoprt/videoprt.c | 21 +++++++++++- reactos/ntoskrnl/io/driver.c | 40 ++++++++++++++--------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/reactos/drivers/video/videoprt/videoprt.c b/reactos/drivers/video/videoprt/videoprt.c index 493c4092314..1fd9552a5f4 100644 --- a/reactos/drivers/video/videoprt/videoprt.c +++ b/reactos/drivers/video/videoprt/videoprt.c @@ -587,7 +587,26 @@ VideoPortInitialize( } DriverExtension->HwContext = HwContext; - RtlCopyMemory(&DriverExtension->RegistryPath, RegistryPath, sizeof(UNICODE_STRING)); + /* we can't use RtlDuplicateUnicodeString because only ntdll exposes it... */ + if (RegistryPath->Length != 0) + { + DriverExtension->RegistryPath.Length = 0; + DriverExtension->RegistryPath.MaximumLength = RegistryPath->Length + sizeof(UNICODE_NULL); + DriverExtension->RegistryPath.Buffer = ExAllocatePoolWithTag(PagedPool, + DriverExtension->RegistryPath.MaximumLength, + TAG('U', 'S', 'T', 'R')); + if (DriverExtension->RegistryPath.Buffer == NULL) + { + RtlInitUnicodeString(&DriverExtension->RegistryPath, NULL); + return STATUS_INSUFFICIENT_RESOURCES; + } + + RtlCopyUnicodeString(&DriverExtension->RegistryPath, RegistryPath); + } + else + { + RtlInitUnicodeString(&DriverExtension->RegistryPath, NULL); + } switch (HwInitializationData->HwInitDataSize) { diff --git a/reactos/ntoskrnl/io/driver.c b/reactos/ntoskrnl/io/driver.c index 092ac55f3e9..a2fee3a0718 100644 --- a/reactos/ntoskrnl/io/driver.c +++ b/reactos/ntoskrnl/io/driver.c @@ -544,10 +544,29 @@ IopInitializeDriverModule( IN BOOLEAN FileSystemDriver, OUT PDRIVER_OBJECT *DriverObject) { + const WCHAR ServicesKeyName[] = L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"; UNICODE_STRING RegistryKey; - PDRIVER_INITIALIZE DriverEntry = ModuleObject->EntryPoint; + PDRIVER_INITIALIZE DriverEntry; NTSTATUS Status; - WCHAR ServicesKeyName[] = L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"; + + DriverEntry = ModuleObject->EntryPoint; + + if (ServiceName != NULL && ServiceName->Length != 0) + { + RegistryKey.Length = 0; + RegistryKey.MaximumLength = sizeof(ServicesKeyName) + ServiceName->Length; + RegistryKey.Buffer = ExAllocatePool(PagedPool, RegistryKey.MaximumLength); + if (RegistryKey.Buffer == NULL) + { + return STATUS_INSUFFICIENT_RESOURCES; + } + RtlAppendUnicodeToString(&RegistryKey, ServicesKeyName); + RtlAppendUnicodeStringToString(&RegistryKey, ServiceName); + } + else + { + RtlInitUnicodeString(&RegistryKey, NULL); + } Status = IopCreateDriverObject( DriverObject, @@ -563,26 +582,15 @@ IopInitializeDriverModule( return Status; } - if (ServiceName->Buffer) - { - RegistryKey.Length = ServiceName->Length + - sizeof(ServicesKeyName) - sizeof(UNICODE_NULL); - RegistryKey.MaximumLength = RegistryKey.Length + sizeof(UNICODE_NULL); - RegistryKey.Buffer = ExAllocatePool(PagedPool, RegistryKey.MaximumLength); - wcscpy(RegistryKey.Buffer, ServicesKeyName); - wcscat(RegistryKey.Buffer, ServiceName->Buffer); - } - else - { - RtlInitUnicodeString(&RegistryKey, NULL); - } - DPRINT("RegistryKey: %wZ\n", &RegistryKey); DPRINT("Calling driver entrypoint at %08lx\n", DriverEntry); IopMarkLastReinitializeDriver(); Status = DriverEntry(*DriverObject, &RegistryKey); + + RtlFreeUnicodeString(&RegistryKey); + if (!NT_SUCCESS(Status)) { ObMakeTemporaryObject(*DriverObject);