diff options
author | Oliver Smith-Denny <osde@microsoft.com> | 2024-10-03 10:23:33 -0700 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-10-29 02:09:18 +0000 |
commit | 040afc1e3be6e3d334c2483803b0470a34bced55 (patch) | |
tree | 857c69039e886a39337aac982c1c850d91b7c331 /ShellPkg | |
parent | 2d10dc1fb5a12a186b4401ce42fdd3f38a614037 (diff) | |
download | edk2-040afc1e3be6e3d334c2483803b0470a34bced55.tar.gz edk2-040afc1e3be6e3d334c2483803b0470a34bced55.tar.bz2 edk2-040afc1e3be6e3d334c2483803b0470a34bced55.zip |
ShellPkg: UefiShellDebug1CommandsLib: CodeQL Fixes
Includes changes across the module for the following CodeQL rules:
- cpp/comparison-with-wider-type
- cpp/overflow-buffer
- cpp/redundant-null-check-param
- cpp/uselesstest
Co-authored-by: Taylor Beebe <taylor.d.beebe@gmail.com>
Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
Diffstat (limited to 'ShellPkg')
24 files changed, 161 insertions, 30 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c index e94236d0b9..e031aa3c0b 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c @@ -280,7 +280,13 @@ ShellCommandRunComp ( 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"comp", TempParam);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ return (ShellStatus);
+ }
+
FileName1 = ShellFindFilePath (TempParam);
if (FileName1 == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
@@ -294,7 +300,13 @@ ShellCommandRunComp ( }
TempParam = ShellCommandLineGetRawValue (Package, 2);
- ASSERT (TempParam != NULL);
+ if (TempParam == NULL) {
+ ASSERT (TempParam != NULL);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ return (ShellStatus);
+ }
+
FileName2 = ShellFindFilePath (TempParam);
if (FileName2 == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
@@ -367,7 +379,7 @@ ShellCommandRunComp ( }
if (ShellStatus == SHELL_SUCCESS) {
- while (DiffPointNumber < DifferentCount) {
+ while ((UINT64)DiffPointNumber < DifferentCount) {
DataSizeFromFile1 = 1;
DataSizeFromFile2 = 1;
OneByteFromFile1 = 0;
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c index 5329b559ba..a9aa483e4c 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dblk.c @@ -111,6 +111,8 @@ ShellCommandRunDblk ( UINT64 BlockCount;
EFI_DEVICE_PATH_PROTOCOL *DevPath;
+ Lba = 0;
+ BlockCount = 0;
ShellStatus = SHELL_SUCCESS;
Status = EFI_SUCCESS;
@@ -186,7 +188,7 @@ ShellCommandRunDblk ( //
// do the work if we have a valid block identifier
//
- if (gEfiShellProtocol->GetDevicePathFromMap (BlockName) == NULL) {
+ if ((BlockName == NULL) || (gEfiShellProtocol->GetDevicePathFromMap (BlockName) == NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dblk", BlockName);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c index 975db0a620..b81099c734 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c @@ -448,7 +448,11 @@ CascadeProcessVariables ( StrnCatGrow (&FoundVarName, &NameSize, PrevName, 0);
} else {
FoundVarName = AllocateZeroPool (sizeof (CHAR16));
- NameSize = sizeof (CHAR16);
+ if (FoundVarName == NULL) {
+ return (SHELL_OUT_OF_RESOURCES);
+ }
+
+ NameSize = sizeof (CHAR16);
}
Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c index f5edc1bdbb..7d7721d4ee 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c @@ -101,8 +101,14 @@ ShellCommandRunEdit ( //
if (ShellCommandLineGetCount (Package) == 2) {
TempParam = ShellCommandLineGetRawValue (Package, 1);
- ASSERT (TempParam != NULL);
- FileBufferSetFileName (TempParam);
+ if (TempParam == NULL) {
+ ASSERT (TempParam != NULL);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"edit");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ FileBufferSetFileName (TempParam);
+ }
+
// if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {
// Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
// if (!EFI_ERROR(Status)) {
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c index 58beaaf9c5..f3ea38438d 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c @@ -1378,7 +1378,9 @@ MainCommandDisplayHelp ( //
for (CurrentLine = 0; 0 != MainMenuHelpInfo[CurrentLine]; CurrentLine++) {
InfoString = HiiGetString (gShellDebug1HiiHandle, MainMenuHelpInfo[CurrentLine], NULL);
- ShellPrintEx (0, CurrentLine+1, L"%E%s%N", InfoString);
+ if (InfoString != NULL) {
+ ShellPrintEx (0, CurrentLine+1, L"%E%s%N", InfoString);
+ }
}
//
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c index 3284f0c1e2..c9eace1ac9 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c @@ -107,6 +107,9 @@ MenuBarRefresh ( //
for (Item = MenuItems; Item != NULL && Item->Function != NULL; Item++) {
NameString = HiiGetString (gShellDebug1HiiHandle, Item->NameToken, NULL);
+ if (NameString == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
Width = MAX ((StrLen (NameString) + 6), 20);
if (((Col + Width) > LastCol)) {
@@ -115,6 +118,10 @@ MenuBarRefresh ( }
FunctionKeyString = HiiGetString (gShellDebug1HiiHandle, Item->FunctionKeyToken, NULL);
+ if (FunctionKeyString == NULL) {
+ FreePool (NameString);
+ return EFI_INVALID_PARAMETER;
+ }
ShellPrintEx ((INT32)(Col) - 1, (INT32)(Row) - 1, L"%E%s%N %H%s%N ", FunctionKeyString, NameString);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c index d581a334f4..d2d642b194 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c @@ -79,10 +79,15 @@ ShellCommandRunEfiCompress ( 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"eficompress");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+
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"eficompress", TempParam);
ShellStatus = SHELL_NOT_FOUND;
} else {
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);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c index d8818dd958..3b18241149 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c @@ -371,6 +371,10 @@ HFileImageSave ( // set status string
//
Str = CatSPrint (NULL, L"%d Lines Written", NumLines);
+ if (Str == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
StatusBarSetStatusString (Str);
FreePool (Str);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c index 0eb917acf7..e33adc39f9 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c @@ -115,7 +115,9 @@ HMainCommandDisplayHelp ( ,
NULL
);
- ShellPrintEx (0, CurrentLine+1, L"%E%s%N", InfoString);
+ if (InfoString != NULL) {
+ ShellPrintEx (0, CurrentLine+1, L"%E%s%N", InfoString);
+ }
}
//
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c index 852d6dcf80..3fc635c254 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c @@ -302,6 +302,11 @@ LoadEfiDriversFromRomImage ( );
if (!EFI_ERROR (Status)) {
DecompressedImageBuffer = AllocateZeroPool (DestinationSize);
+ if (DecompressedImageBuffer == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"loadpcirom");
+ return EFI_OUT_OF_RESOURCES;
+ }
+
if (ImageBuffer != NULL) {
Scratch = AllocateZeroPool (ScratchSize);
if (Scratch != NULL) {
@@ -333,6 +338,10 @@ LoadEfiDriversFromRomImage ( //
UnicodeSPrint (RomFileName, sizeof (RomFileName), L"%s[%d]", FileName, ImageIndex);
FilePath = FileDevicePath (NULL, RomFileName);
+ if (FilePath == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_LOAD_FAIL), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex);
+ return EFI_OUT_OF_RESOURCES;
+ }
Status = gBS->LoadImage (
TRUE,
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c index a089953b28..a061c97d07 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c @@ -214,7 +214,12 @@ ShellCommandRunMemMap ( if (Status == EFI_BUFFER_TOO_SMALL) {
Size += SIZE_1KB;
Descriptors = AllocateZeroPool (Size);
- Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version);
+ if (Descriptors == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"memmap");
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ }
+
+ Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version);
}
if (EFI_ERROR (Status)) {
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c index b75e2f4770..cff2c9daee 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c @@ -537,7 +537,13 @@ ShellCommandRunMm ( goto Done;
}
- Temp = ShellCommandLineGetRawValue (Package, 1);
+ Temp = ShellCommandLineGetRawValue (Package, 1);
+ if (Temp == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mm", L"NULL");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
+
Status = ShellConvertStringToUint64 (Temp, &Address, TRUE, FALSE);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mm", Temp);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c index d907ddd415..c0e288632d 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c @@ -67,14 +67,20 @@ ShellCommandRunMode ( ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetCount (Package) == 3) {
Temp = ShellCommandLineGetRawValue (Package, 1);
- if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) {
+ if (Temp == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
ShellStatus = SHELL_INVALID_PARAMETER;
}
NewCol = ShellStrToUintn (Temp);
Temp = ShellCommandLineGetRawValue (Package, 2);
- if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) {
+ if (Temp == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
ShellStatus = SHELL_INVALID_PARAMETER;
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c index 93622733a5..ff5c44527a 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -5765,7 +5765,7 @@ PrintInterpretedExtendedCompatibilityDynamicPowerAllocation ( )
{
CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_DYNAMIC_POWER_ALLOCATION *Header;
- UINT8 LinkCount;
+ UINT32 LinkCount;
Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_DYNAMIC_POWER_ALLOCATION *)HeaderAddress;
@@ -5780,7 +5780,7 @@ PrintInterpretedExtendedCompatibilityDynamicPowerAllocation ( Header->DpaStatus,
Header->DpaControl
);
- for (LinkCount = 0; LinkCount < PCI_EXPRESS_EXTENDED_CAPABILITY_DYNAMIC_POWER_ALLOCATION_GET_SUBSTATE_MAX (Header) + 1; LinkCount++) {
+ for (LinkCount = 0; LinkCount < PCI_EXPRESS_EXTENDED_CAPABILITY_DYNAMIC_POWER_ALLOCATION_GET_SUBSTATE_MAX (Header) + (UINT32)1; LinkCount++) {
ShellPrintHiiEx (
-1,
-1,
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c index 99cc448942..a33343dc72 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SerMode.c @@ -288,7 +288,13 @@ ShellCommandRunSerMode ( goto Done;
}
- Temp = ShellCommandLineGetRawValue (Package, 5);
+ Temp = ShellCommandLineGetRawValue (Package, 5);
+ if (Temp == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
+
Value = ShellStrToUintn (Temp);
switch (Value) {
case 0:
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c index e5bacde638..807347200b 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c @@ -62,7 +62,11 @@ ShellCommandRunSetSize ( NewSize = 0;
} else {
Temp1 = ShellCommandLineGetRawValue (Package, 1);
- if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE)) {
+ if (Temp1 == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ NewSize = 0;
+ } else if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize");
ShellStatus = SHELL_INVALID_PARAMETER;
NewSize = 0;
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c index 61788d1993..2f119b6ae6 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c @@ -285,7 +285,10 @@ GetVariableDataFromParameter ( for (Index = 2; Index < ShellCommandLineGetCount (Package); Index++) {
TempData = ShellCommandLineGetRawValue (Package, Index);
- ASSERT (TempData != NULL);
+ if (TempData == NULL) {
+ ASSERT (TempData != NULL);
+ return EFI_INVALID_PARAMETER;
+ }
if (TempData[0] != L'=') {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", TempData);
@@ -401,11 +404,21 @@ ShellCommandRunSetVar ( ShellStatus = SHELL_INVALID_PARAMETER;
} else {
VariableName = ShellCommandLineGetRawValue (Package, 1);
+ if (VariableName == NULL) {
+ return SHELL_INVALID_PARAMETER;
+ }
+
if (!ShellCommandLineGetFlag (Package, L"-guid")) {
CopyGuid (&Guid, &gEfiGlobalVariableGuid);
} else {
StringGuid = ShellCommandLineGetValue (Package, L"-guid");
- RStatus = StrToGuid (StringGuid, &Guid);
+ if (StringGuid != NULL) {
+ RStatus = StrToGuid (StringGuid, &Guid);
+ } else {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid);
+ return SHELL_INVALID_PARAMETER;
+ }
+
if (RETURN_ERROR (RStatus) || (StringGuid[GUID_STRING_LENGTH] != L'\0')) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid);
ShellStatus = SHELL_INVALID_PARAMETER;
@@ -419,6 +432,11 @@ ShellCommandRunSetVar ( Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
Buffer = AllocateZeroPool (Size);
+ if (Buffer == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar");
+ return SHELL_OUT_OF_RESOURCES;
+ }
+
Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer);
}
@@ -440,6 +458,11 @@ ShellCommandRunSetVar ( Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
Buffer = AllocateZeroPool (Size);
+ if (Buffer == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar");
+ return SHELL_OUT_OF_RESOURCES;
+ }
+
Status = gRT->GetVariable ((CHAR16 *)VariableName, &Guid, &Attributes, &Size, Buffer);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c index 80199c9cc5..54e08874e3 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c @@ -676,7 +676,7 @@ SmbiosPrintStructure ( {
UINTN NumOfDevice;
NumOfDevice = (Struct->Type10->Hdr.Length - sizeof (SMBIOS_STRUCTURE)) / (2 * sizeof (UINT8));
- for (Index = 0; Index < NumOfDevice; Index++) {
+ for (Index = 0; (UINTN)Index < NumOfDevice; Index++) {
ShellPrintEx (-1, -1, (((Struct->Type10->Device[Index].DeviceType) & 0x80) != 0) ? L"Device Enabled\n" : L"Device Disabled\n");
DisplayOnboardDeviceTypes ((Struct->Type10->Device[Index].DeviceType) & 0x7F, Option);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_DESC_STRING), gShellDebug1HiiHandle);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c index 7e7eef3fd8..982e20ead4 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c @@ -790,7 +790,7 @@ InitSmbios64BitTableStatistics ( //
Handle = INVALID_HANDLE;
LibGetSmbios64BitStructure (&Handle, NULL, NULL);
- for (Index = 1; Index <= mNumberOfSmbios64BitStructures; Index++) {
+ for (Index = 1; (UINTN)Index <= mNumberOfSmbios64BitStructures; Index++) {
//
// If reach the end of table, break..
//
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c index a1a055928f..d61a61e734 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c @@ -269,6 +269,10 @@ EditGetDefaultFileName ( do {
FileNameTmp = CatSPrint (NULL, L"NewFile%d.%s", Suffix, Extension);
+ if (FileNameTmp == NULL) {
+ ASSERT (FileNameTmp != NULL);
+ return NULL;
+ }
//
// after that filename changed to path
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.h index e738b34490..35768dba00 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.h +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.h @@ -50,6 +50,7 @@ #include <Library/DevicePathLib.h>
#include <Library/PrintLib.h>
#include <Library/HandleParsingLib.h>
+#include <Library/SafeIntLib.h>
extern EFI_HII_HANDLE gShellDebug1HiiHandle;
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf index 140e9dc644..91b48e81f9 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf @@ -111,6 +111,7 @@ SortLib
PrintLib
BcfgCommandLib
+ SafeIntLib
[Pcd]
gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize ## CONSUMES
diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc index 029a22fc79..5303a68959 100644 --- a/ShellPkg/ShellPkg.dsc +++ b/ShellPkg/ShellPkg.dsc @@ -65,6 +65,8 @@ DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
+ SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
+
# StackCheckLib is not linked for SEC modules by default, this package can link it against its SEC modules
[LibraryClasses.common.SEC]
NULL|MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf
|