From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: hao.a.wu@intel.com) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by groups.io with SMTP; Tue, 23 Apr 2019 22:05:52 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Apr 2019 22:05:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,388,1549958400"; d="scan'208";a="340269821" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.8]) by fmsmga006.fm.intel.com with ESMTP; 23 Apr 2019 22:05:51 -0700 From: "Wu, Hao A" To: devel@edk2.groups.io Cc: Hao Wu , Ard Biesheuvel , Michael D Kinney , Liming Gao , Jian J Wang Subject: [PATCH v2] MdeModulePkg/DxeCore: Please static checker for false report Date: Wed, 24 Apr 2019 13:05:49 +0800 Message-Id: <20190424050549.6760-1-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 After commit 57df17fe26, some static check reports suspicous NULL pointer deference at line: Entry->MachineType = Entry->Emulator->MachineType; ^^^^^^^^^^^^^^^ within function PeCoffEmuProtocolNotify(). However, 'Entry->Emulator' is guaranteed to have a non-NULL value when previous call to the CoreHandleProtocol() returns EFI_SUCCESS. This commit will re-write the return status check for CoreHandleProtocol() to add explicit NULL pointer check for protocol instance pointer. Cc: Ard Biesheuvel Cc: Michael D Kinney Cc: Liming Gao Cc: Jian J Wang Signed-off-by: Hao Wu --- MdeModulePkg/Core/Dxe/Image/Image.c | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 08306a73fd..de5b8bed27 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -134,12 +134,14 @@ PeCoffEmuProtocolNotify ( IN VOID *Context ) { - EFI_STATUS Status; - UINTN BufferSize; - EFI_HANDLE EmuHandle; - EMULATOR_ENTRY *Entry; + EFI_STATUS Status; + UINTN BufferSize; + EFI_HANDLE EmuHandle; + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emulator; + EMULATOR_ENTRY *Entry; EmuHandle = NULL; + Emulator = NULL; while (TRUE) { BufferSize = sizeof (EmuHandle); @@ -157,16 +159,19 @@ PeCoffEmuProtocolNotify ( return; } - Entry = AllocateZeroPool (sizeof (*Entry)); - ASSERT (Entry != NULL); - Status = CoreHandleProtocol ( EmuHandle, &gEdkiiPeCoffImageEmulatorProtocolGuid, - (VOID **)&Entry->Emulator + (VOID **)&Emulator ); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status) || Emulator == NULL) { + continue; + } + + Entry = AllocateZeroPool (sizeof (*Entry)); + ASSERT (Entry != NULL); + Entry->Emulator = Emulator; Entry->MachineType = Entry->Emulator->MachineType; InsertTailList (&mAvailableEmulators, &Entry->Link); -- 2.12.0.windows.1