public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ard.biesheuvel@linaro.org>
To: Hao Wu <hao.a.wu@intel.com>
Cc: edk2-devel-groups-io <devel@edk2.groups.io>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	 Liming Gao <liming.gao@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>
Subject: Re: [PATCH v2] MdeModulePkg/DxeCore: Please static checker for false report
Date: Wed, 24 Apr 2019 09:07:15 +0200	[thread overview]
Message-ID: <CAKv+Gu8EJ=fCpO6cauHHh9PdVVnBWMLBK7BfdfCNL7G6w6KB-Q@mail.gmail.com> (raw)
In-Reply-To: <20190424050549.6760-1-hao.a.wu@intel.com>

On Wed, 24 Apr 2019 at 07:05, Hao Wu <hao.a.wu@intel.com> wrote:
>
> 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 <ard.biesheuvel@linaro.org>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>

Again, I think it is rather unfortunate that we need code changes such
as this one just to remove warnings from a flawed static analyzer. But
the change looks correct to me, so

Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> ---
>  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
>

  reply	other threads:[~2019-04-24  7:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24  5:05 [PATCH v2] MdeModulePkg/DxeCore: Please static checker for false report Wu, Hao A
2019-04-24  7:07 ` Ard Biesheuvel [this message]
2019-04-26  5:38   ` Wu, Hao A
2019-04-26  7:32     ` Liming Gao
2019-04-26 14:50     ` Michael D Kinney
2019-04-28  0:33       ` Wu, Hao A

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKv+Gu8EJ=fCpO6cauHHh9PdVVnBWMLBK7BfdfCNL7G6w6KB-Q@mail.gmail.com' \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox