public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg/CapsuleApp: Fix potential NULL pointer dereference issue
@ 2019-02-11  6:11 Chen A Chen
  2019-02-11 13:02 ` Wu, Hao A
  0 siblings, 1 reply; 4+ messages in thread
From: Chen A Chen @ 2019-02-11  6:11 UTC (permalink / raw)
  To: edk2-devel; +Cc: Chen A Chen, Jian J Wang, Hao Wu, Liming Gao

To avoid potential NULL pointer dereference issue. Initialize them at
the beginning of the function. This patch is a supplement which was missed
at e98212cb5d59fff8f385d9179ad7f1a3ce9cf215 commit.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
---
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c  | 23 +++++++++++++---------
 .../Application/CapsuleApp/CapsuleOnDisk.c         |  5 ++++-
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index 33d2ecc582..cbbfda1424 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -1001,12 +1001,15 @@ DumpProvisionedCapsule (
   EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
   EFI_SHELL_PROTOCOL              *ShellProtocol;
 
-  ShellProtocol = GetShellProtocol ();
-
   Index             = 0;
   CapsuleDataPtr64  = NULL;
   BootNext          = NULL;
-  ShellProtocol     = NULL;
+
+  ShellProtocol = GetShellProtocol ();
+  if (ShellProtocol == NULL) {
+    Print (L"Get Shell Protocol Fail\n");
+    return ;
+  }
 
   //
   // Dump capsule provisioned on Memory
@@ -1033,16 +1036,16 @@ DumpProvisionedCapsule (
               (VOID **) &CapsuleDataPtr64,
               NULL
               );
-    if (EFI_ERROR (Status)) {
+    if (EFI_ERROR (Status) || CapsuleDataPtr64 == NULL) {
       if (Index == 0) {
         Print (L"No data.\n");
       }
       break;
-    } else {
-      Index++;
-      Print (L"Capsule Description at 0x%08x\n", *CapsuleDataPtr64);
-      DumpBlockDescriptors ((EFI_CAPSULE_BLOCK_DESCRIPTOR*) (UINTN) *CapsuleDataPtr64, DumpCapsuleInfo);
     }
+
+    Index++;
+    Print (L"Capsule Description at 0x%08x\n", *CapsuleDataPtr64);
+    DumpBlockDescriptors ((EFI_CAPSULE_BLOCK_DESCRIPTOR*) (UINTN) *CapsuleDataPtr64, DumpCapsuleInfo);
   }
 
   //
@@ -1057,7 +1060,9 @@ DumpProvisionedCapsule (
              (VOID **) &BootNext,
              NULL
             );
-  if (!EFI_ERROR (Status)) {
+  if (EFI_ERROR (Status) || BootNext == NULL) {
+    Print (L"Get BootNext Variable Fail. Status = %r\n", Status);
+  } else {
     UnicodeSPrint (BootOptionName, sizeof (BootOptionName), L"Boot%04x", *BootNext);
     Status = EfiBootManagerVariableToLoadOption (BootOptionName, &BootNextOptionEntry);
     if (!EFI_ERROR (Status)) {
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
index 4faa863bca..f6e46cbdb1 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
@@ -445,7 +445,10 @@ GetUpdateFileSystem (
                (VOID **)&BootNextData,
                NULL
                );
-    if (!EFI_ERROR (Status)) {
+    if (EFI_ERROR (Status) || BootNextData == NULL) {
+      Print (L"Get Boot Next Data Fail. Status = %r\n", Status);
+      return EFI_NOT_FOUND;
+    } else {
       UnicodeSPrint (BootOptionName, sizeof (BootOptionName), L"Boot%04x", *BootNextData);
       Status = EfiBootManagerVariableToLoadOption (BootOptionName, &BootNextOption);
       if (!EFI_ERROR (Status)) {
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] MdeModulePkg/CapsuleApp: Fix potential NULL pointer dereference issue
@ 2019-02-01  2:06 Chen A Chen
  2019-02-02  5:21 ` Gao, Liming
  0 siblings, 1 reply; 4+ messages in thread
From: Chen A Chen @ 2019-02-01  2:06 UTC (permalink / raw)
  To: edk2-devel; +Cc: Chen A Chen, Jian J Wang, Hao Wu

To avoid potential NULL pointer dereference issue. Initialize them at
the beginning of the function.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
---
 MdeModulePkg/Application/CapsuleApp/CapsuleApp.c    |  5 +++--
 MdeModulePkg/Application/CapsuleApp/CapsuleDump.c   | 17 +++++++++++------
 MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c | 17 +++++++++++++++--
 3 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
index 896acd3304..198a63555d 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
@@ -916,8 +916,9 @@ UefiMain (
   EFI_GUID                      ImageTypeId;
   UINTN                         ImageIndex;
 
-  MapFsStr = NULL;
-  CapsuleNum = 0;
+  BlockDescriptors  = NULL;
+  MapFsStr          = NULL;
+  CapsuleNum        = 0;
 
   Status = GetArg();
   if (EFI_ERROR(Status)) {
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
index 5bf617c5f6..7bef5a1378 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
@@ -795,11 +795,13 @@ DumpCapsuleFromDisk (
   UINTN                                         FileCount;
   BOOLEAN                                       NoFile;
 
-  DirHandle  = NULL;
-  FileHandle = NULL;
-  Index      = 0;
-  FileCount  = 0;
-  NoFile     = FALSE;
+  DirHandle       = NULL;
+  FileHandle      = NULL;
+  Index           = 0;
+  FileInfoBuffer  = NULL;
+  FileInfo        = NULL;
+  FileCount       = 0;
+  NoFile          = FALSE;
 
   Status = Fs->OpenVolume (Fs, &Root);
   if (EFI_ERROR (Status)) {
@@ -970,7 +972,10 @@ DumpProvisionedCapsule (
 
   ShellProtocol = GetShellProtocol ();
 
-  Index = 0;
+  Index             = 0;
+  CapsuleDataPtr64  = NULL;
+  BootNext          = NULL;
+  ShellProtocol     = NULL;
 
   //
   // Dump capsule provisioned on Memory
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
index 393b7ae7db..4faa863bca 100644
--- a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
+++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
@@ -151,9 +151,14 @@ DumpAllEfiSysPartition (
   UINTN                      NumberEfiSystemPartitions;
   EFI_SHELL_PROTOCOL         *ShellProtocol;
 
-  ShellProtocol = GetShellProtocol ();
   NumberEfiSystemPartitions = 0;
 
+  ShellProtocol = GetShellProtocol ();
+  if (ShellProtocol == NULL) {
+    Print (L"Get Shell Protocol Fail\n");;
+    return ;
+  }
+
   Print (L"EFI System Partition list:\n");
 
   gBS->LocateHandleBuffer (
@@ -421,7 +426,13 @@ GetUpdateFileSystem (
   EFI_BOOT_MANAGER_LOAD_OPTION    NewOption;
 
   MappedDevicePath = NULL;
+  BootOptionBuffer = NULL;
+
   ShellProtocol = GetShellProtocol ();
+  if (ShellProtocol == NULL) {
+    Print (L"Get Shell Protocol Fail\n");;
+    return EFI_NOT_FOUND;
+  }
 
   //
   // 1. If Fs is not assigned and there are capsule provisioned before,
@@ -468,7 +479,9 @@ GetUpdateFileSystem (
   // 2. Get EFI system partition form boot options.
   //
   BootOptionBuffer = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
-  if (BootOptionCount == 0 && Map == NULL) {
+  if ( (BootOptionBuffer == NULL) ||
+       (BootOptionCount == 0 && Map == NULL)
+     ) {
     return EFI_NOT_FOUND;
   }
 
-- 
2.16.2.windows.1



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

end of thread, other threads:[~2019-02-11 13:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-11  6:11 [PATCH] MdeModulePkg/CapsuleApp: Fix potential NULL pointer dereference issue Chen A Chen
2019-02-11 13:02 ` Wu, Hao A
  -- strict thread matches above, loose matches on Subject: below --
2019-02-01  2:06 Chen A Chen
2019-02-02  5:21 ` Gao, Liming

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