diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2016-07-12 17:52:41 +0800 |
---|---|---|
committer | Hao Wu <hao.a.wu@intel.com> | 2016-07-25 11:04:27 +0800 |
commit | 4be5831a51e8d330726170f96f35f08d55702fdc (patch) | |
tree | 4b53b7bcd3a7847f3da21efd157b9c0159f3c2ae /ShellPkg/Library/UefiShellDebug1CommandsLib | |
parent | edc956244162245bbba365f11209a3efa35ab99c (diff) | |
download | edk2-platforms-4be5831a51e8d330726170f96f35f08d55702fdc.tar.xz |
ShellPkg/EfiCompress: 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 ca1b2411f5bcdc0b023f331afd9a9e741752067e)
Diffstat (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib')
-rw-r--r-- | ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c index 85ae732521..d94acf4e4b 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c @@ -2,7 +2,7 @@ Main file for EfiCompress shell Debug1 function.
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
- Copyright (c) 2005 - 2011, 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
@@ -116,20 +116,26 @@ ShellCommandRunEfiCompress ( Status = gEfiShellProtocol->GetFileSize(InShellFileHandle, &InSize);
ASSERT_EFI_ERROR(Status);
InBuffer = AllocateZeroPool((UINTN)InSize);
- ASSERT(InBuffer != NULL);
- InSize2 = (UINTN)InSize;
- Status = gEfiShellProtocol->ReadFile(InShellFileHandle, &InSize2, InBuffer);
- InSize = InSize2;
- ASSERT_EFI_ERROR(Status);
- Status = Compress(InBuffer, InSize, OutBuffer, &OutSize);
- if (Status == EFI_BUFFER_TOO_SMALL) {
- OutBuffer = AllocateZeroPool((UINTN)OutSize);
- ASSERT(OutBuffer != NULL);
- Status = Compress(InBuffer, InSize, OutBuffer, &OutSize);
+ if (InBuffer == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ InSize2 = (UINTN) InSize;
+ Status = gEfiShellProtocol->ReadFile (InShellFileHandle, &InSize2, InBuffer);
+ InSize = InSize2;
+ ASSERT_EFI_ERROR (Status);
+ Status = Compress (InBuffer, InSize, OutBuffer, &OutSize);
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ OutBuffer = AllocateZeroPool ((UINTN) OutSize);
+ if (OutBuffer == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ Status = Compress (InBuffer, InSize, OutBuffer, &OutSize);
+ }
+ }
}
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status);
- ShellStatus = SHELL_DEVICE_ERROR;
+ ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR);
} else {
OutSize2 = (UINTN)OutSize;
Status = gEfiShellProtocol->WriteFile(OutShellFileHandle, &OutSize2, OutBuffer);
|