MdeModulePkg/DxeCore: Please static checker for false report

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>
This commit is contained in:
Hao Wu 2019-04-22 13:42:18 +08:00
parent 20029ca22b
commit dfaa565559
1 changed files with 14 additions and 9 deletions

View File

@ -134,12 +134,14 @@ PeCoffEmuProtocolNotify (
IN VOID *Context IN VOID *Context
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN BufferSize; UINTN BufferSize;
EFI_HANDLE EmuHandle; EFI_HANDLE EmuHandle;
EMULATOR_ENTRY *Entry; EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emulator;
EMULATOR_ENTRY *Entry;
EmuHandle = NULL; EmuHandle = NULL;
Emulator = NULL;
while (TRUE) { while (TRUE) {
BufferSize = sizeof (EmuHandle); BufferSize = sizeof (EmuHandle);
@ -157,16 +159,19 @@ PeCoffEmuProtocolNotify (
return; return;
} }
Entry = AllocateZeroPool (sizeof (*Entry));
ASSERT (Entry != NULL);
Status = CoreHandleProtocol ( Status = CoreHandleProtocol (
EmuHandle, EmuHandle,
&gEdkiiPeCoffImageEmulatorProtocolGuid, &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; Entry->MachineType = Entry->Emulator->MachineType;
InsertTailList (&mAvailableEmulators, &Entry->Link); InsertTailList (&mAvailableEmulators, &Entry->Link);