don't leak the registry path string after initializing a driver Modified: trunk/reactos/drivers/video/videoprt/videoprt.c Modified: trunk/reactos/ntoskrnl/io/driver.c _____
Modified: trunk/reactos/drivers/video/videoprt/videoprt.c --- trunk/reactos/drivers/video/videoprt/videoprt.c 2005-05-05 22:40:05 UTC (rev 15027) +++ trunk/reactos/drivers/video/videoprt/videoprt.c 2005-05-06 00:07:05 UTC (rev 15028) @@ -587,8 +587,27 @@
} 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) { /* _____
Modified: trunk/reactos/ntoskrnl/io/driver.c --- trunk/reactos/ntoskrnl/io/driver.c 2005-05-05 22:40:05 UTC (rev 15027) +++ trunk/reactos/ntoskrnl/io/driver.c 2005-05-06 00:07:05 UTC (rev 15028) @@ -544,10 +544,29 @@
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 @@ 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);