ShellPkg/EfiDecompress: Handle memory allocation failure
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
Main file for EfiDecompress shell Debug1 function.
|
Main file for EfiDecompress shell Debug1 function.
|
||||||
|
|
||||||
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
||||||
Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -119,7 +119,9 @@ ShellCommandRunEfiDecompress (
|
|||||||
InSize = (UINTN)Temp64Bit;
|
InSize = (UINTN)Temp64Bit;
|
||||||
ASSERT_EFI_ERROR(Status);
|
ASSERT_EFI_ERROR(Status);
|
||||||
InBuffer = AllocateZeroPool(InSize);
|
InBuffer = AllocateZeroPool(InSize);
|
||||||
ASSERT(InBuffer != NULL);
|
if (InBuffer == NULL) {
|
||||||
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
} else {
|
||||||
Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer);
|
Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
@ -127,6 +129,8 @@ ShellCommandRunEfiDecompress (
|
|||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32) InSize, &OutSize, &ScratchSize);
|
Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32) InSize, &OutSize, &ScratchSize);
|
||||||
|
}
|
||||||
|
|
||||||
if (EFI_ERROR(Status) || OutSize == 0) {
|
if (EFI_ERROR(Status) || OutSize == 0) {
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName);
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName);
|
||||||
ShellStatus = SHELL_NOT_FOUND;
|
ShellStatus = SHELL_NOT_FOUND;
|
||||||
@ -138,15 +142,17 @@ ShellCommandRunEfiDecompress (
|
|||||||
} else {
|
} else {
|
||||||
OutBuffer = AllocateZeroPool(OutSize);
|
OutBuffer = AllocateZeroPool(OutSize);
|
||||||
ScratchBuffer = AllocateZeroPool(ScratchSize);
|
ScratchBuffer = AllocateZeroPool(ScratchSize);
|
||||||
ASSERT(OutBuffer != NULL);
|
if (OutBuffer == NULL || ScratchBuffer == NULL) {
|
||||||
ASSERT(ScratchBuffer != NULL);
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
} else {
|
||||||
Status = Decompress->Decompress (Decompress, InBuffer, (UINT32) InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize);
|
Status = Decompress->Decompress (Decompress, InBuffer, (UINT32) InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize);
|
||||||
ASSERT_EFI_ERROR(Status);
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status);
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status);
|
||||||
ShellStatus = SHELL_DEVICE_ERROR;
|
ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR);
|
||||||
} else {
|
} else {
|
||||||
OutSizeTemp = OutSize;
|
OutSizeTemp = OutSize;
|
||||||
Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer);
|
Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer);
|
||||||
@ -159,8 +165,6 @@ ShellCommandRunEfiDecompress (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ShellCommandLineFreeVarList (Package);
|
ShellCommandLineFreeVarList (Package);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user