summaryrefslogtreecommitdiffstats
path: root/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c
diff options
context:
space:
mode:
Diffstat (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c')
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c
index 72f8c087cb..af75d75036 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c
@@ -85,10 +85,16 @@ ShellCommandRunEfiDecompress (
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
TempParam = ShellCommandLineGetRawValue (Package, 1);
- ASSERT (TempParam != NULL);
+ if (TempParam == NULL) {
+ ASSERT (TempParam != NULL);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"efidecompress");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ return (ShellStatus);
+ }
+
InFileName = ShellFindFilePath (TempParam);
OutFileName = ShellCommandLineGetRawValue (Package, 2);
- if (InFileName == NULL) {
+ if ((InFileName == NULL) || (OutFileName == NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"efidecompress", TempParam);
ShellStatus = SHELL_NOT_FOUND;
} else {
@@ -112,13 +118,25 @@ ShellCommandRunEfiDecompress (
if (ShellStatus == SHELL_SUCCESS) {
Status = FileHandleGetSize (InFileHandle, &Temp64Bit);
- ASSERT_EFI_ERROR (Status);
- if (!EFI_ERROR (Status)) {
- ASSERT (Temp64Bit <= (UINT32)(-1));
- InSize = (UINTN)Temp64Bit;
- InBuffer = AllocateZeroPool (InSize);
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"efidecompress", ShellCommandLineGetRawValue (Package, 1));
+ ShellStatus = SHELL_NOT_FOUND;
+ }
+ }
+
+ if (ShellStatus == SHELL_SUCCESS) {
+ //
+ // Limit the File Size to UINT32, even though calls accept UINTN.
+ // 32 bits = 4gb.
+ //
+ Status = SafeUint64ToUint32 (Temp64Bit, (UINT32 *)&InSize);
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ ShellStatus = SHELL_BAD_BUFFER_SIZE;
+ goto Done;
}
+ InBuffer = AllocateZeroPool (InSize);
if (InBuffer == NULL) {
Status = EFI_OUT_OF_RESOURCES;
} else {
@@ -166,6 +184,8 @@ ShellCommandRunEfiDecompress (
}
}
+Done:
+
ShellCommandLineFreeVarList (Package);
}