From 09a43a5d5ce9285b27551d7909f038e350b360d9 Mon Sep 17 00:00:00 2001 From: Jaben Carsey Date: Wed, 14 May 2014 16:54:09 +0000 Subject: ShellPkg: report error when EfiDecompress is run on a non-compressed file Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey Reviewed-by: Tapan Shah Reviewed-by: Erik Bjorge git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15529 6f19259b-4bc3-4df7-8a09-765794883524 --- .../UefiShellDebug1CommandsLib/EfiDecompress.c | 54 +++++++++++---------- .../UefiShellDebug1CommandsLib.uni | Bin 171002 -> 171274 bytes 2 files changed, 29 insertions(+), 25 deletions(-) (limited to 'ShellPkg/Library') diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c index 35a32f1f3b..bae4464e5c 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c @@ -1,7 +1,7 @@ /** @file Main file for EfiDecompress shell Debug1 function. - Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.
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 @@ -110,11 +110,6 @@ ShellCommandRunEfiDecompress ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status); ShellStatus = SHELL_NOT_FOUND; } - Status = ShellOpenFileByName(OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); - if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status); - ShellStatus = SHELL_NOT_FOUND; - } } if (ShellStatus == SHELL_SUCCESS) { @@ -131,27 +126,36 @@ ShellCommandRunEfiDecompress ( ASSERT_EFI_ERROR(Status); Status = Decompress->GetInfo(Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize); - ASSERT_EFI_ERROR(Status); - - 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 (EFI_ERROR(Status) || OutSize == 0) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName); + ShellStatus = SHELL_NOT_FOUND; } else { - OutSizeTemp = OutSize; - Status = gEfiShellProtocol->WriteFile(OutFileHandle, &OutSizeTemp, OutBuffer); - OutSize = (UINT32)OutSizeTemp; + Status = ShellOpenFileByName(OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, OutFileName, Status); - ShellStatus = SHELL_DEVICE_ERROR; - } + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status); + ShellStatus = SHELL_NOT_FOUND; + } 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; + } 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, OutFileName, Status); + ShellStatus = SHELL_DEVICE_ERROR; + } + } + } } } } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni index 65d058fc4b..eb38d40459 100644 Binary files a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni and b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni differ -- cgit v1.2.3