[edk2] [Patch] MdeModulePkg HiiDataBase: Fix the potential NULL pointer access

Liming Gao posted 1 patch 6 years, 12 months ago
Failed in applying to current master (apply log)
MdeModulePkg/Universal/HiiDatabaseDxe/Database.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
[edk2] [Patch] MdeModulePkg HiiDataBase: Fix the potential NULL pointer access
Posted by Liming Gao 6 years, 12 months ago
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Universal/HiiDatabaseDxe/Database.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
index 4a2dc8d030..e8f4564e64 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
@@ -721,9 +721,14 @@ FindQuestionDefaultSetting (
       VariableStorage = NULL;
     }
     Entry = AllocatePool (sizeof (VARSTORAGE_DEFAULT_DATA));
-    Entry->DefaultId = DefaultId;
-    Entry->VariableStorage = VariableStorage;
-    InsertTailList (&gVarStorageList, &Entry->Entry);
+    if (Entry != NULL) {
+      Entry->DefaultId = DefaultId;
+      Entry->VariableStorage = VariableStorage;
+      InsertTailList (&gVarStorageList, &Entry->Entry);
+    } else if (VariableStorage != NULL) {
+      FreePool (VariableStorage);
+      VariableStorage = NULL;
+    }
   }
   //
   // The matched variable storage is not found.
-- 
2.11.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] MdeModulePkg HiiDataBase: Fix the potential NULL pointer access
Posted by Zeng, Star 6 years, 12 months ago
Reviewed-by: Star Zeng <star.zeng@intel.com>

Thanks,
Star
-----Original Message-----
From: Gao, Liming 
Sent: Thursday, December 28, 2017 12:54 PM
To: edk2-devel@lists.01.org
Cc: Zeng, Star <star.zeng@intel.com>
Subject: [Patch] MdeModulePkg HiiDataBase: Fix the potential NULL pointer access

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Universal/HiiDatabaseDxe/Database.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
index 4a2dc8d030..e8f4564e64 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
@@ -721,9 +721,14 @@ FindQuestionDefaultSetting (
       VariableStorage = NULL;
     }
     Entry = AllocatePool (sizeof (VARSTORAGE_DEFAULT_DATA));
-    Entry->DefaultId = DefaultId;
-    Entry->VariableStorage = VariableStorage;
-    InsertTailList (&gVarStorageList, &Entry->Entry);
+    if (Entry != NULL) {
+      Entry->DefaultId = DefaultId;
+      Entry->VariableStorage = VariableStorage;
+      InsertTailList (&gVarStorageList, &Entry->Entry);
+    } else if (VariableStorage != NULL) {
+      FreePool (VariableStorage);
+      VariableStorage = NULL;
+    }
   }
   //
   // The matched variable storage is not found.
-- 
2.11.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel