From d18634c026eeba286699b35a1e10d58c0b0ba4bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Thu, 18 Feb 2021 10:24:53 +0100 Subject: [PATCH] [NTOS:WMI] Be consistent about potential NULL pointer use --- ntoskrnl/wmi/wmi.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ntoskrnl/wmi/wmi.c b/ntoskrnl/wmi/wmi.c index 7d6d2bb21a8..1b6a70e923f 100644 --- a/ntoskrnl/wmi/wmi.c +++ b/ntoskrnl/wmi/wmi.c @@ -108,21 +108,26 @@ NTSTATUS NTAPI IoWMIWriteEvent(_Inout_ PVOID WnodeEventItem) { - DPRINT1("IoWMIWriteEvent() called for WnodeEventItem %p (Flags = 0x%08lx), returning success\n", - WnodeEventItem, ((PWNODE_HEADER)WnodeEventItem)->Flags); + PWNODE_HEADER Header = WnodeEventItem; - if (((PWNODE_HEADER)WnodeEventItem)->Flags & WNODE_FLAG_TRACED_GUID) + if(!Header) { - DPRINT("IoWMIWriteEvent(): Flags has WNODE_FLAG_TRACED_GUID\n"); + DPRINT1("Got NULL Item!\n"); + return STATUS_INVALID_PARAMETER; + } + DPRINT1("IoWMIWriteEvent() called for WnodeEventItem %p (Flags = 0x%08lx), returning success\n", + WnodeEventItem, Header->Flags); + + if (Header->Flags & WNODE_FLAG_TRACED_GUID) + { // Never free WnodeEventItem in this case. - + DPRINT("IoWMIWriteEvent(): Flags has WNODE_FLAG_TRACED_GUID\n"); return STATUS_SUCCESS; } /* Free the buffer if we are returning success */ - if (WnodeEventItem != NULL) - ExFreePool(WnodeEventItem); + ExFreePool(WnodeEventItem); return STATUS_SUCCESS; } @@ -402,7 +407,7 @@ WmiStartTrace(IN OUT PWMI_LOGGER_INFORMATION LoggerInfo) UNIMPLEMENTED; return STATUS_NOT_IMPLEMENTED; } - + NTSTATUS NTAPI WmiStopTrace(IN PWMI_LOGGER_INFORMATION LoggerInfo)