public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference.
@ 2018-05-05 20:21 Marvin Häuser
  2018-05-17  8:04 ` Ni, Ruiyu
  0 siblings, 1 reply; 4+ messages in thread
From: Marvin Häuser @ 2018-05-05 20:21 UTC (permalink / raw)
  To: edk2-devel@lists.01.org; +Cc: michael.d.kinney@intel.com, liming.gao@intel.com

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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference.
  2018-05-05 20:21 [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference Marvin Häuser
@ 2018-05-17  8:04 ` Ni, Ruiyu
  0 siblings, 0 replies; 4+ messages in thread
From: Ni, Ruiyu @ 2018-05-17  8:04 UTC (permalink / raw)
  To: Marvin Häuser, edk2-devel@lists.01.org
  Cc: Kinney, Michael D, Gao, Liming

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference
@ 2019-10-20 12:08 Marvin Häuser
  2019-10-21  3:12 ` Liming Gao
  0 siblings, 1 reply; 4+ messages in thread
From: Marvin Häuser @ 2019-10-20 12:08 UTC (permalink / raw)
  To: devel@edk2.groups.io; +Cc: vit9696@protonmail.com, Michael D Kinney, Liming Gao

From: Marvin Haeuser <mhaeuser@outlook.de>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2293

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

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Marvin Haeuser <mhaeuser@outlook.de>
---
 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 96913c5c02b8..5dc893833a46 100644
--- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
+++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
@@ -68,19 +68,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.23.0.windows.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference
  2019-10-20 12:08 Marvin Häuser
@ 2019-10-21  3:12 ` Liming Gao
  0 siblings, 0 replies; 4+ messages in thread
From: Liming Gao @ 2019-10-21  3:12 UTC (permalink / raw)
  To: Marvin.Haeuser@outlook.com, devel@edk2.groups.io
  Cc: vit9696@protonmail.com, Kinney, Michael D

Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: Marvin Häuser [mailto:Marvin.Haeuser@outlook.com]
>Sent: Sunday, October 20, 2019 8:09 PM
>To: devel@edk2.groups.io
>Cc: vit9696@protonmail.com; Kinney, Michael D
><michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>
>Subject: [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference
>
>From: Marvin Haeuser <mhaeuser@outlook.de>
>
>REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2293
>
>Move the NULL check in FileHandleGetInfo() to directly after the
>allocation to prevent potential NULL dereferences.
>
>Cc: Michael D Kinney <michael.d.kinney@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>Signed-off-by: Marvin Haeuser <mhaeuser@outlook.de>
>---
> 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 96913c5c02b8..5dc893833a46 100644
>--- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
>+++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
>@@ -68,19 +68,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.23.0.windows.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-21  3:12 UTC | newest]

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox