public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ruiyu" <ruiyu.ni@intel.com>
To: "Marvin Häuser" <Marvin.Haeuser@outlook.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Kinney, Michael D" <michael.d.kinney@intel.com>,
	"Gao, Liming" <liming.gao@intel.com>
Subject: Re: [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference.
Date: Thu, 17 May 2018 08:04:30 +0000	[thread overview]
Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BC9E8E9@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <VI1PR0801MB17904FD71A039FD9E581E12780850@VI1PR0801MB1790.eurprd08.prod.outlook.com>

Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

Thanks/Ray

> -----Original Message-----
> From: edk2-devel <edk2-devel-bounces@lists.01.org> On Behalf Of Marvin
> Häuser
> Sent: Sunday, May 6, 2018 4:22 AM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming
> <liming.gao@intel.com>
> Subject: [edk2] [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL
> dereference.
> 
> Move the NULL-check in FileHandleGetInfo() to directly after the
> allocation to prevent potential NULL dereferences.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marvin Haeuser <Marvin.Haeuser@outlook.com>
> ---
>  MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c | 30 +++++++++++---
> ------
>  1 file changed, 16 insertions(+), 14 deletions(-)
> 
> diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
> b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
> index 57aad77bc135..bcf3a328b82d 100644
> --- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
> +++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Provides interface to EFI_FILE_HANDLE functionality.
> 
> -  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved. <BR>
> +  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. <BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at
> @@ -74,19 +74,21 @@ FileHandleGetInfo (
>      // error is expected.  getting size to allocate
>      //
>      FileInfo = AllocateZeroPool(FileInfoSize);
> -    //
> -    // now get the information
> -    //
> -    Status = FileHandle->GetInfo(FileHandle,
> -                                 &gEfiFileInfoGuid,
> -                                 &FileInfoSize,
> -                                 FileInfo);
> -    //
> -    // if we got an error free the memory and return NULL
> -    //
> -    if (EFI_ERROR(Status) && (FileInfo != NULL)) {
> -      FreePool(FileInfo);
> -      FileInfo = NULL;
> +    if (FileInfo != NULL) {
> +      //
> +      // now get the information
> +      //
> +      Status = FileHandle->GetInfo(FileHandle,
> +                                   &gEfiFileInfoGuid,
> +                                   &FileInfoSize,
> +                                   FileInfo);
> +      //
> +      // if we got an error free the memory and return NULL
> +      //
> +      if (EFI_ERROR(Status)) {
> +        FreePool(FileInfo);
> +        FileInfo = NULL;
> +      }
>      }
>    }
>    return (FileInfo);
> --
> 2.17.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


  reply	other threads:[~2018-05-17  8:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-05 20:21 [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference Marvin Häuser
2018-05-17  8:04 ` Ni, Ruiyu [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-10-20 12:08 Marvin Häuser
2019-10-21  3:12 ` Liming Gao

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=734D49CCEBEEF84792F5B80ED585239D5BC9E8E9@SHSMSX104.ccr.corp.intel.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