]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/DxeCore: Please static checker for false report
authorHao Wu <hao.a.wu@intel.com>
Mon, 22 Apr 2019 05:42:18 +0000 (13:42 +0800)
committerHao Wu <hao.a.wu@intel.com>
Sun, 28 Apr 2019 00:31:38 +0000 (08:31 +0800)
After commit 57df17fe26, some static check reports suspicious 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: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
MdeModulePkg/Core/Dxe/Image/Image.c

index 08306a73fdbfd5ecdb1252b52ecdb7b5e20f5db9..de5b8bed27ad6c019dcf1925a52f30898c39a10c 100644 (file)
@@ -134,12 +134,14 @@ PeCoffEmuProtocolNotify (
   IN  VOID            *Context\r
   )\r
 {\r
-  EFI_STATUS          Status;\r
-  UINTN               BufferSize;\r
-  EFI_HANDLE          EmuHandle;\r
-  EMULATOR_ENTRY      *Entry;\r
+  EFI_STATUS                            Status;\r
+  UINTN                                 BufferSize;\r
+  EFI_HANDLE                            EmuHandle;\r
+  EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL  *Emulator;\r
+  EMULATOR_ENTRY                        *Entry;\r
 \r
   EmuHandle = NULL;\r
+  Emulator  = NULL;\r
 \r
   while (TRUE) {\r
     BufferSize = sizeof (EmuHandle);\r
@@ -157,16 +159,19 @@ PeCoffEmuProtocolNotify (
       return;\r
     }\r
 \r
-    Entry = AllocateZeroPool (sizeof (*Entry));\r
-    ASSERT (Entry != NULL);\r
-\r
     Status = CoreHandleProtocol (\r
                EmuHandle,\r
                &gEdkiiPeCoffImageEmulatorProtocolGuid,\r
-               (VOID **)&Entry->Emulator\r
+               (VOID **)&Emulator\r
                );\r
-    ASSERT_EFI_ERROR (Status);\r
+    if (EFI_ERROR (Status) || Emulator == NULL) {\r
+      continue;\r
+    }\r
+\r
+    Entry = AllocateZeroPool (sizeof (*Entry));\r
+    ASSERT (Entry != NULL);\r
 \r
+    Entry->Emulator    = Emulator;\r
     Entry->MachineType = Entry->Emulator->MachineType;\r
 \r
     InsertTailList (&mAvailableEmulators, &Entry->Link);\r