[NTOS:PNP] Fix bug causing all devices be considered as already existing

We should compare against DeviceObject as DeviceInstance is never NULL.
Fix a resource leak as well. The bug CORE-18983 seems to lay somewhere
else though, I just stumbled upon this one while researching it.

Note there is a BSOD in the PnP manager on reboot after the driver
installation failure, but it seems it was uncovered by the fix
as opposed to caused by it.
This commit is contained in:
Sophie Lemos 2023-05-26 17:42:36 +01:00 committed by Stanislav Motylkov
parent fa388640ca
commit 29a706fc5a

View file

@ -218,15 +218,14 @@ IopInitializeDevice(
/* Leave, if the device already exists */
DeviceObject = IopGetDeviceObjectFromDeviceInstance(&DeviceInstance);
if (DeviceInstance.Buffer != NULL)
if (DeviceObject != NULL)
{
DPRINT1("Device %wZ already exists!\n", &DeviceInstance);
ObDereferenceObject(DeviceObject);
Status = STATUS_SUCCESS;
goto done;
}
ObDereferenceObject(DeviceObject);
DPRINT("Device %wZ does not exist!\n", &DeviceInstance);
/* Create a device node for the device instance */