From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=chen.a.chen@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0CC37208D6135 for ; Sun, 10 Feb 2019 22:11:30 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Feb 2019 22:11:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,358,1544515200"; d="scan'208";a="317945847" Received: from chenche4.ccr.corp.intel.com ([10.239.9.12]) by fmsmga006.fm.intel.com with ESMTP; 10 Feb 2019 22:11:28 -0800 From: Chen A Chen To: edk2-devel@lists.01.org Cc: Chen A Chen , Jian J Wang , Hao Wu , Liming Gao Date: Mon, 11 Feb 2019 14:11:26 +0800 Message-Id: <20190211061126.45552-1-chen.a.chen@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 Subject: [PATCH] MdeModulePkg/CapsuleApp: Fix potential NULL pointer dereference issue X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Feb 2019 06:11:31 -0000 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 Cc: Hao Wu Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Chen A Chen --- 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