summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2016-07-12 18:00:01 +0800
committerHao Wu <hao.a.wu@intel.com>2016-07-25 11:04:31 +0800
commit23f12576d02eb199e5f8aca42d93bcacd3fef8c8 (patch)
treec90999f395cada70c284561074792026544cb48e
parent4be5831a51e8d330726170f96f35f08d55702fdc (diff)
downloadedk2-platforms-23f12576d02eb199e5f8aca42d93bcacd3fef8c8.tar.xz
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> (cherry picked from commit aba0ca78c6a96433af9dba74e4e56487b0c27d2e)
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c52
1 files changed, 28 insertions, 24 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c
index c1457430d8..90eafe570b 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c
@@ -2,7 +2,7 @@
Main file for EfiDecompress shell Debug1 function.
(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
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
@@ -119,14 +119,18 @@ ShellCommandRunEfiDecompress (
InSize = (UINTN)Temp64Bit;
ASSERT_EFI_ERROR(Status);
InBuffer = AllocateZeroPool(InSize);
- ASSERT(InBuffer != NULL);
- Status = gEfiShellProtocol->ReadFile(InFileHandle, &InSize, InBuffer);
- ASSERT_EFI_ERROR(Status);
+ if (InBuffer == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer);
+ ASSERT_EFI_ERROR (Status);
- Status = gBS->LocateProtocol(&gEfiDecompressProtocolGuid, NULL, (VOID**)&Decompress);
- ASSERT_EFI_ERROR(Status);
+ Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID**) &Decompress);
+ 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) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName);
ShellStatus = SHELL_NOT_FOUND;
@@ -138,25 +142,25 @@ ShellCommandRunEfiDecompress (
} else {
OutBuffer = AllocateZeroPool(OutSize);
ScratchBuffer = AllocateZeroPool(ScratchSize);
- ASSERT(OutBuffer != NULL);
- ASSERT(ScratchBuffer != NULL);
-
- Status = Decompress->Decompress(Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize);
- ASSERT_EFI_ERROR(Status);
-
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status);
- ShellStatus = SHELL_DEVICE_ERROR;
+ if (OutBuffer == NULL || ScratchBuffer == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
} else {
- OutSizeTemp = OutSize;
- Status = gEfiShellProtocol->WriteFile(OutFileHandle, &OutSizeTemp, OutBuffer);
- OutSize = (UINT32)OutSizeTemp;
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"efidecompress", OutFileName, Status);
- ShellStatus = SHELL_DEVICE_ERROR;
- }
+ Status = Decompress->Decompress (Decompress, InBuffer, (UINT32) InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize);
}
- }
+ }
+ }
+
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status);
+ ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR);
+ } else {
+ OutSizeTemp = OutSize;
+ Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer);
+ OutSize = (UINT32) OutSizeTemp;
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"efidecompress", OutFileName, Status);
+ ShellStatus = SHELL_DEVICE_ERROR;
+ }
}
}
}