public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marvin Häuser" <Marvin.Haeuser@outlook.com>
To: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "michael.d.kinney@intel.com" <michael.d.kinney@intel.com>,
	"liming.gao@intel.com" <liming.gao@intel.com>
Subject: [PATCH v2] MdePkg/UefiFileHandleLib: Fix potential NULL dereference.
Date: Thu, 17 May 2018 12:41:39 +0000	[thread overview]
Message-ID: <VI1PR0801MB17902A183BC5849E1516B4FD80910@VI1PR0801MB1790.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <396ef0a31f51da8581a8100ed1c6a6358974038e.1526560735.git.Marvin.Haeuser@outlook.com>

Move the NULL-check in FileHandleGetInfo() to directly after the
allocation to prevent potential NULL dereferences.

V2:
  - Do not change the copyright date as requested.
  - Added R-bs from V1 as no functional changes have been made.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marvin Haeuser <Marvin.Haeuser@outlook.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
---
 MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c | 28 +++++++++++---------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
index 57aad77bc135..5b3d39ef6103 100644
--- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
+++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
@@ -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



       reply	other threads:[~2018-05-17 12:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <396ef0a31f51da8581a8100ed1c6a6358974038e.1526560735.git.Marvin.Haeuser@outlook.com>
2018-05-17 12:41 ` Marvin Häuser [this message]
2018-05-17 12:41 ` [PATCH v2] MdePkg/UefiFileHandleLib: Fix the Root directory determination Marvin Häuser
2018-06-13 20:27   ` Marvin Häuser
2018-06-14  5:43   ` Ni, Ruiyu
2018-05-17 12:41 ` [PATCH v2] MdePkg: Update MmSwDispatch.h's references to SmmSw2Dispatch Marvin Häuser
2018-05-23  2:42   ` Gao, Liming

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=VI1PR0801MB17902A183BC5849E1516B4FD80910@VI1PR0801MB1790.eurprd08.prod.outlook.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