From 29a706fc5ad0a1b169688b86d19f12ef1552c07a Mon Sep 17 00:00:00 2001 From: Sophie Lemos Date: Fri, 26 May 2023 17:42:36 +0100 Subject: [PATCH] [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. --- ntoskrnl/io/pnpmgr/plugplay.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ntoskrnl/io/pnpmgr/plugplay.c b/ntoskrnl/io/pnpmgr/plugplay.c index 46585458b84..461328c8651 100644 --- a/ntoskrnl/io/pnpmgr/plugplay.c +++ b/ntoskrnl/io/pnpmgr/plugplay.c @@ -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 */