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);