diff --git a/reactos/ntoskrnl/include/internal/io.h b/reactos/ntoskrnl/include/internal/io.h index 326f19c4dc6..bec9be6d1b4 100644 --- a/reactos/ntoskrnl/include/internal/io.h +++ b/reactos/ntoskrnl/include/internal/io.h @@ -208,6 +208,16 @@ (_DeviceTreeTraverseContext)->Action = (_Action); \ (_DeviceTreeTraverseContext)->Context = (_Context); } +/* + * BOOLEAN + * IopIsValidPhysicalDeviceObject( + * IN PDEVICE_OBJECT PhysicalDeviceObject); + */ +#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject) \ + (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject) && \ + (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode) && \ + (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode->Flags & DNF_ENUMERATED)) + // // Device List Operations // diff --git a/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c b/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c index 06f1405045d..055f9351d1d 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c @@ -3527,9 +3527,9 @@ IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, } else { - DeviceNode = IopGetDeviceNode(DeviceObject); - if (!DeviceNode) + if (!IopIsValidPhysicalDeviceObject(DeviceObject)) return STATUS_INVALID_DEVICE_REQUEST; + DeviceNode = IopGetDeviceNode(DeviceObject); KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) + DeviceNode->InstancePath.Length; }