mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-31 01:24:12 +02:00
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>
This commit is contained in:
parent
c87bb070a6
commit
ca1b2411f5
@ -2,7 +2,7 @@
|
|||||||
Main file for EfiCompress shell Debug1 function.
|
Main file for EfiCompress 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 - 2011, 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
|
||||||
@ -116,20 +116,26 @@ ShellCommandRunEfiCompress (
|
|||||||
Status = gEfiShellProtocol->GetFileSize(InShellFileHandle, &InSize);
|
Status = gEfiShellProtocol->GetFileSize(InShellFileHandle, &InSize);
|
||||||
ASSERT_EFI_ERROR(Status);
|
ASSERT_EFI_ERROR(Status);
|
||||||
InBuffer = AllocateZeroPool((UINTN)InSize);
|
InBuffer = AllocateZeroPool((UINTN)InSize);
|
||||||
ASSERT(InBuffer != NULL);
|
if (InBuffer == NULL) {
|
||||||
InSize2 = (UINTN)InSize;
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
Status = gEfiShellProtocol->ReadFile(InShellFileHandle, &InSize2, InBuffer);
|
} else {
|
||||||
InSize = InSize2;
|
InSize2 = (UINTN) InSize;
|
||||||
ASSERT_EFI_ERROR(Status);
|
Status = gEfiShellProtocol->ReadFile (InShellFileHandle, &InSize2, InBuffer);
|
||||||
Status = Compress(InBuffer, InSize, OutBuffer, &OutSize);
|
InSize = InSize2;
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
OutBuffer = AllocateZeroPool((UINTN)OutSize);
|
Status = Compress (InBuffer, InSize, OutBuffer, &OutSize);
|
||||||
ASSERT(OutBuffer != NULL);
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
Status = Compress(InBuffer, InSize, OutBuffer, &OutSize);
|
OutBuffer = AllocateZeroPool ((UINTN) OutSize);
|
||||||
|
if (OutBuffer == NULL) {
|
||||||
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
} else {
|
||||||
|
Status = Compress (InBuffer, InSize, OutBuffer, &OutSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, 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 {
|
} else {
|
||||||
OutSize2 = (UINTN)OutSize;
|
OutSize2 = (UINTN)OutSize;
|
||||||
Status = gEfiShellProtocol->WriteFile(OutShellFileHandle, &OutSize2, OutBuffer);
|
Status = gEfiShellProtocol->WriteFile(OutShellFileHandle, &OutSize2, OutBuffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user