MdeModulePkg/CapsuleApp: Fix potential NULL pointer dereference issue

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>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Chen A Chen 2019-02-01 10:06:49 +08:00 committed by Liming Gao
parent aad4e2ec8f
commit e98212cb5d
3 changed files with 29 additions and 10 deletions

View File

@ -916,8 +916,9 @@ UefiMain (
EFI_GUID ImageTypeId; EFI_GUID ImageTypeId;
UINTN ImageIndex; UINTN ImageIndex;
MapFsStr = NULL; BlockDescriptors = NULL;
CapsuleNum = 0; MapFsStr = NULL;
CapsuleNum = 0;
Status = GetArg(); Status = GetArg();
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {

View File

@ -795,11 +795,13 @@ DumpCapsuleFromDisk (
UINTN FileCount; UINTN FileCount;
BOOLEAN NoFile; BOOLEAN NoFile;
DirHandle = NULL; DirHandle = NULL;
FileHandle = NULL; FileHandle = NULL;
Index = 0; Index = 0;
FileCount = 0; FileInfoBuffer = NULL;
NoFile = FALSE; FileInfo = NULL;
FileCount = 0;
NoFile = FALSE;
Status = Fs->OpenVolume (Fs, &Root); Status = Fs->OpenVolume (Fs, &Root);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -970,7 +972,10 @@ DumpProvisionedCapsule (
ShellProtocol = GetShellProtocol (); ShellProtocol = GetShellProtocol ();
Index = 0; Index = 0;
CapsuleDataPtr64 = NULL;
BootNext = NULL;
ShellProtocol = NULL;
// //
// Dump capsule provisioned on Memory // Dump capsule provisioned on Memory

View File

@ -151,9 +151,14 @@ DumpAllEfiSysPartition (
UINTN NumberEfiSystemPartitions; UINTN NumberEfiSystemPartitions;
EFI_SHELL_PROTOCOL *ShellProtocol; EFI_SHELL_PROTOCOL *ShellProtocol;
ShellProtocol = GetShellProtocol ();
NumberEfiSystemPartitions = 0; NumberEfiSystemPartitions = 0;
ShellProtocol = GetShellProtocol ();
if (ShellProtocol == NULL) {
Print (L"Get Shell Protocol Fail\n");;
return ;
}
Print (L"EFI System Partition list:\n"); Print (L"EFI System Partition list:\n");
gBS->LocateHandleBuffer ( gBS->LocateHandleBuffer (
@ -421,7 +426,13 @@ GetUpdateFileSystem (
EFI_BOOT_MANAGER_LOAD_OPTION NewOption; EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
MappedDevicePath = NULL; MappedDevicePath = NULL;
BootOptionBuffer = NULL;
ShellProtocol = GetShellProtocol (); 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, // 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. // 2. Get EFI system partition form boot options.
// //
BootOptionBuffer = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); BootOptionBuffer = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
if (BootOptionCount == 0 && Map == NULL) { if ( (BootOptionBuffer == NULL) ||
(BootOptionCount == 0 && Map == NULL)
) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }