summaryrefslogtreecommitdiffstats
path: root/ShellPkg
diff options
context:
space:
mode:
authorOliver Smith-Denny <osde@microsoft.com>2024-10-03 10:31:31 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-10-29 02:09:18 +0000
commit334f5748869996eee994f9dee41f3e6a3d9bd087 (patch)
treedc0956044dac9de2d2d6443f3c01cc922b75ec4e /ShellPkg
parentc80c222198a88847f3e1ce3e482af8e4c0bd36fa (diff)
downloadedk2-334f5748869996eee994f9dee41f3e6a3d9bd087.tar.gz
ShellPkg: 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')
-rw-r--r--ShellPkg/Application/Shell/Shell.c2
-rw-r--r--ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c118
-rw-r--r--ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c62
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c5
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c2
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c7
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c2
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c2
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c1
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c3
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c2
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c4
-rw-r--r--ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c23
-rw-r--r--ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c13
-rw-r--r--ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c8
-rw-r--r--ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c4
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c4
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c1
-rw-r--r--ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c5
-rw-r--r--ShellPkg/Library/UefiShellLib/UefiShellLib.c5
-rw-r--r--ShellPkg/Library/UefiShellNetwork2CommandsLib/Ifconfig6.c12
21 files changed, 225 insertions, 60 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index 173ec8c5d4..9bacf9d8c7 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -1331,7 +1331,7 @@ DoStartupScript (
}
Status = RunShellCommand (FileStringPath, &CalleeStatus);
- if ((!EFI_ERROR (Status)) && (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit == TRUE)) {
+ if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit == TRUE) {
ShellCommandRegisterExit (gEfiShellProtocol->BatchIsActive (), (UINT64)CalleeStatus);
}
diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
index 781da4d55d..1e3ba1b0a9 100644
--- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
+++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
@@ -299,6 +299,9 @@ LoadedImageProtocolDumpInformation (
SHELL_FREE_NON_NULL (Temp);
SHELL_FREE_NON_NULL (FileName);
+ if (RetVal == NULL) {
+ return NULL;
+ }
}
Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_LI_DUMP_MAIN), NULL);
@@ -309,24 +312,25 @@ LoadedImageProtocolDumpInformation (
PdbFileName = PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase);
DataType = ConvertMemoryType (LoadedImage->ImageDataType);
CodeType = ConvertMemoryType (LoadedImage->ImageCodeType);
-
- RetVal = CatSPrint (
- RetVal,
- Temp,
- LoadedImage->Revision,
- LoadedImage->ParentHandle,
- LoadedImage->SystemTable,
- LoadedImage->DeviceHandle,
- FilePath,
- PdbFileName,
- LoadedImage->LoadOptionsSize,
- LoadedImage->LoadOptions,
- LoadedImage->ImageBase,
- LoadedImage->ImageSize,
- CodeType,
- DataType,
- LoadedImage->Unload
- );
+ if ((PdbFileName != NULL) && (DataType != NULL) && (CodeType != NULL) && (FilePath != NULL)) {
+ RetVal = CatSPrint (
+ RetVal,
+ Temp,
+ LoadedImage->Revision,
+ LoadedImage->ParentHandle,
+ LoadedImage->SystemTable,
+ LoadedImage->DeviceHandle,
+ FilePath,
+ PdbFileName,
+ LoadedImage->LoadOptionsSize,
+ LoadedImage->LoadOptions,
+ LoadedImage->ImageBase,
+ LoadedImage->ImageSize,
+ CodeType,
+ DataType,
+ LoadedImage->Unload
+ );
+ }
SHELL_FREE_NON_NULL (Temp);
SHELL_FREE_NON_NULL (FilePath);
@@ -389,6 +393,10 @@ GraphicsOutputProtocolDumpInformation (
}
Fmt = ConvertPixelFormat (GraphicsOutput->Mode->Info->PixelFormat);
+ if (Fmt == NULL) {
+ SHELL_FREE_NON_NULL (Temp);
+ return NULL;
+ }
RetVal = CatSPrint (
NULL,
@@ -409,6 +417,9 @@ GraphicsOutputProtocolDumpInformation (
);
SHELL_FREE_NON_NULL (Temp);
+ if (RetVal == NULL) {
+ goto EXIT;
+ }
Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_GOP_RES_LIST_MAIN), NULL);
if (Temp == NULL) {
@@ -509,6 +520,9 @@ EdidDiscoveredProtocolDumpInformation (
RetVal = CatSPrint (NULL, Temp, EdidDiscovered->SizeOfEdid);
SHELL_FREE_NON_NULL (Temp);
+ if (RetVal == NULL) {
+ return NULL;
+ }
if (EdidDiscovered->SizeOfEdid != 0) {
Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_DISCOVERED_DATA), NULL);
@@ -575,6 +589,9 @@ EdidActiveProtocolDumpInformation (
RetVal = CatSPrint (NULL, Temp, EdidActive->SizeOfEdid);
SHELL_FREE_NON_NULL (Temp);
+ if (RetVal == NULL) {
+ return NULL;
+ }
if (EdidActive->SizeOfEdid != 0) {
Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_ACTIVE_DATA), NULL);
@@ -790,6 +807,9 @@ TxtOutProtocolDumpInformation (
Size = (Dev->Mode->MaxMode + 1) * 80;
RetVal = AllocateZeroPool (Size);
+ if (RetVal == NULL) {
+ return NULL;
+ }
Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_TXT_OUT_DUMP_HEADER), NULL);
if (Temp != NULL) {
@@ -801,6 +821,11 @@ TxtOutProtocolDumpInformation (
// Dump TextOut Info
//
Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_TXT_OUT_DUMP_LINE), NULL);
+ if (Temp == NULL) {
+ FreePool (RetVal);
+ return NULL;
+ }
+
for (Index = 0; Index < Dev->Mode->MaxMode; Index++) {
Status = Dev->QueryMode (Dev, Index, &Col, &Row);
NewSize = Size - StrSize (RetVal);
@@ -1056,6 +1081,10 @@ BusSpecificDriverOverrideProtocolDumpInformation (
ConvertHandleToHandleIndex (ImageHandle),
ConvertDevicePathToText (LoadedImage->FilePath, TRUE, TRUE)
);
+ if (TempRetVal == NULL) {
+ break;
+ }
+
StrnCatGrow (&RetVal, &Size, TempRetVal, 0);
SHELL_FREE_NON_NULL (TempRetVal);
}
@@ -1287,6 +1316,11 @@ PciIoProtocolDumpInformation (
Pci.Hdr.ClassCode[1],
Pci.Hdr.ClassCode[2]
);
+ if (RetVal == NULL) {
+ FreePool (GetString);
+ return NULL;
+ }
+
for (Index = 0; Index < sizeof (Pci); Index++) {
if ((Index % 0x10) == 0) {
TempRetVal = CatSPrint (RetVal, L"\r\n %02x", *((UINT8 *)(&Pci) + Index));
@@ -1435,6 +1469,10 @@ AdapterInformationDumpInformation (
}
RetVal = CatSPrint (NULL, TempStr);
+ if (RetVal == NULL) {
+ goto ERROR_EXIT;
+ }
+
SHELL_FREE_NON_NULL (TempStr);
for (GuidIndex = 0; GuidIndex < InfoTypesBufferCount; GuidIndex++) {
@@ -1726,6 +1764,10 @@ FirmwareManagementDumpInformation (
}
RetVal = CatSPrint (NULL, TempStr, ImageInfoSize);
+ if (RetVal == NULL) {
+ goto ERROR_EXIT;
+ }
+
SHELL_FREE_NON_NULL (TempStr);
//
@@ -1823,37 +1865,65 @@ FirmwareManagementDumpInformation (
} else {
AttributeSettingStr = CatSPrint (NULL, L"(");
+ if (AttributeSettingStr == NULL) {
+ goto ERROR_EXIT;
+ }
+
if ((AttributeSetting & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) != 0x0) {
TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_IMAGE_UPDATABLE");
+ if (TempRetVal == NULL) {
+ goto ERROR_EXIT;
+ }
+
SHELL_FREE_NON_NULL (AttributeSettingStr);
AttributeSettingStr = TempRetVal;
}
if ((AttributeSetting & IMAGE_ATTRIBUTE_RESET_REQUIRED) != 0x0) {
TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_RESET_REQUIRED");
+ if (TempRetVal == NULL) {
+ goto ERROR_EXIT;
+ }
+
SHELL_FREE_NON_NULL (AttributeSettingStr);
AttributeSettingStr = TempRetVal;
}
if ((AttributeSetting & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED) != 0x0) {
TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED");
+ if (TempRetVal == NULL) {
+ goto ERROR_EXIT;
+ }
+
SHELL_FREE_NON_NULL (AttributeSettingStr);
AttributeSettingStr = TempRetVal;
}
if ((AttributeSetting & IMAGE_ATTRIBUTE_IN_USE) != 0x0) {
TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_IN_USE");
+ if (TempRetVal == NULL) {
+ goto ERROR_EXIT;
+ }
+
SHELL_FREE_NON_NULL (AttributeSettingStr);
AttributeSettingStr = TempRetVal;
}
if ((AttributeSetting & IMAGE_ATTRIBUTE_UEFI_IMAGE) != 0x0) {
TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_UEFI_IMAGE");
+ if (TempRetVal == NULL) {
+ goto ERROR_EXIT;
+ }
+
SHELL_FREE_NON_NULL (AttributeSettingStr);
AttributeSettingStr = TempRetVal;
}
TempRetVal = CatSPrint (AttributeSettingStr, L" )");
+ if (TempRetVal == NULL) {
+ goto ERROR_EXIT;
+ }
+
SHELL_FREE_NON_NULL (AttributeSettingStr);
AttributeSettingStr = TempRetVal;
}
@@ -2848,7 +2918,11 @@ GetStringNameFromHandle (
);
if (!EFI_ERROR (Status)) {
BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
- Status = CompNameStruct->GetDriverName (CompNameStruct, BestLang, &RetVal);
+ if (BestLang == NULL) {
+ return (NULL);
+ }
+
+ Status = CompNameStruct->GetDriverName (CompNameStruct, BestLang, &RetVal);
if (BestLang != NULL) {
FreePool (BestLang);
BestLang = NULL;
@@ -2869,7 +2943,11 @@ GetStringNameFromHandle (
);
if (!EFI_ERROR (Status)) {
BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
- Status = CompNameStruct->GetDriverName (CompNameStruct, BestLang, &RetVal);
+ if (BestLang == NULL) {
+ return (NULL);
+ }
+
+ Status = CompNameStruct->GetDriverName (CompNameStruct, BestLang, &RetVal);
if (BestLang != NULL) {
FreePool (BestLang);
}
diff --git a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
index 3ad96647ec..b5617703c7 100644
--- a/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
+++ b/ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.c
@@ -206,6 +206,10 @@ GetBootOptionCrc (
);
if (Status == EFI_BUFFER_TOO_SMALL) {
Buffer = AllocateZeroPool (BufferSize);
+ if (Buffer == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
Status = gRT->GetVariable (
VariableName,
(EFI_GUID *)&gEfiGlobalVariableGuid,
@@ -427,7 +431,12 @@ BcfgMod (
}
if (BcfgOperation->Type == BcfgTypeModh) {
- CurHandle = ConvertHandleIndexToHandle (BcfgOperation->HandleIndex);
+ CurHandle = ConvertHandleIndexToHandle (BcfgOperation->HandleIndex);
+ if (CurHandle == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", L"Handle Number");
+ return (SHELL_INVALID_PARAMETER);
+ }
+
ShellStatus = GetDevicePathByHandle (CurHandle, BcfgOperation->Target, &DevicePathBuffer);
if (ShellStatus == SHELL_SUCCESS) {
DevicePath = DuplicateDevicePath (DevicePathBuffer);
@@ -510,7 +519,12 @@ BcfgMod (
LoadOption.Description = AllocateCopyPool (StrSize (BcfgOperation->Description), BcfgOperation->Description);
} else {
SHELL_FREE_NON_NULL (LoadOption.FilePath);
- LoadOption.FilePath = DuplicateDevicePath (DevicePath);
+ if (DevicePath != NULL) {
+ LoadOption.FilePath = DuplicateDevicePath (DevicePath);
+ } else {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (SHELL_OUT_OF_RESOURCES), gShellBcfgHiiHandle, L"bcfg", OptionStr);
+ goto Done;
+ }
}
Status = EfiBootManagerLoadOptionToVariable (&LoadOption);
@@ -522,6 +536,8 @@ BcfgMod (
EfiBootManagerFreeLoadOption (&LoadOption);
+Done:
+
if (DevicePath != NULL) {
FreePool (DevicePath);
}
@@ -785,10 +801,17 @@ BcfgAdd (
//
// Add the option
//
- DescSize = StrSize (Desc);
- FilePathSize = GetDevicePathSize (FilePath);
+ DescSize = StrSize (Desc);
+ if (FilePath == NULL) {
+ ASSERT (FilePath != NULL);
+ ShellStatus = SHELL_UNSUPPORTED;
+ TempByteBuffer = NULL;
+ } else {
+ FilePathSize = GetDevicePathSize (FilePath);
+
+ TempByteBuffer = AllocateZeroPool (sizeof (UINT32) + sizeof (UINT16) + DescSize + FilePathSize);
+ }
- TempByteBuffer = AllocateZeroPool (sizeof (UINT32) + sizeof (UINT16) + DescSize + FilePathSize);
if (TempByteBuffer != NULL) {
TempByteStart = TempByteBuffer;
*((UINT32 *)TempByteBuffer) = LOAD_OPTION_ACTIVE; // Attributes
@@ -1024,7 +1047,7 @@ BcfgAddOpt (
SHELL_STATUS ShellStatus;
EFI_STATUS Status;
UINT16 OptionIndex;
- UINT16 LoopCounter;
+ UINT32 LoopCounter;
UINT64 Intermediate;
CONST CHAR16 *Temp;
CONST CHAR16 *Walker;
@@ -1093,7 +1116,13 @@ BcfgAddOpt (
}
Temp2 = StrStr (FileName, L"\"");
- ASSERT (Temp2 != NULL);
+ if (Temp2 == NULL) {
+ ASSERT (Temp2 != NULL);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", Walker);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ return (ShellStatus);
+ }
+
Temp2[0] = CHAR_NULL;
Temp2++;
if (StrLen (Temp2) > 0) {
@@ -1363,6 +1392,12 @@ BcfgDisplayDump (
);
if (Status == EFI_BUFFER_TOO_SMALL) {
Buffer = AllocateZeroPool (BufferSize);
+ if (Buffer == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellBcfgHiiHandle, L"bcfg");
+ ++Errors;
+ goto Cleanup;
+ }
+
Status = gRT->GetVariable (
VariableName,
(EFI_GUID *)&gEfiGlobalVariableGuid,
@@ -1403,6 +1438,11 @@ BcfgDisplayDump (
if (LoadOption->FilePathListLength != 0) {
FilePathList = (UINT8 *)Description + DescriptionSize;
DevPathString = ConvertDevicePathToText (FilePathList, TRUE, FALSE);
+ if (DevPathString == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellBcfgHiiHandle, L"bcfg");
+ ++Errors;
+ goto Cleanup;
+ }
}
OptionalDataOffset = sizeof *LoadOption + DescriptionSize +
@@ -1590,6 +1630,12 @@ ShellCommandRunBcfg (
if ((ShellStatus == SHELL_SUCCESS) && (CurrentOperation.Target < BcfgTargetMax)) {
for (ParamNumber = 2; ParamNumber < ShellCommandLineGetCount (Package) && ShellStatus == SHELL_SUCCESS; ParamNumber++) {
CurrentParam = ShellCommandLineGetRawValue (Package, ParamNumber);
+ if (CurrentParam == NULL) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellBcfgHiiHandle, L"bcfg", L"NULL");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Done;
+ }
+
if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16 *)CurrentParam, L"dump") == 0) {
CurrentOperation.Type = BcfgTypeDump;
if (ShellCommandLineGetCount (Package) > 3) {
@@ -1883,6 +1929,8 @@ ShellCommandRunBcfg (
}
}
+Done:
+
if (Package != NULL) {
ShellCommandLineFreeVarList (Package);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c
index e031aa3c0b..26d6653d99 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c
@@ -284,7 +284,7 @@ ShellCommandRunComp (
ASSERT (TempParam != NULL);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam);
ShellStatus = SHELL_INVALID_PARAMETER;
- return (ShellStatus);
+ goto Exit;
}
FileName1 = ShellFindFilePath (TempParam);
@@ -304,7 +304,7 @@ ShellCommandRunComp (
ASSERT (TempParam != NULL);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"comp", TempParam);
ShellStatus = SHELL_INVALID_PARAMETER;
- return (ShellStatus);
+ goto Exit;
}
FileName2 = ShellFindFilePath (TempParam);
@@ -511,6 +511,7 @@ ShellCommandRunComp (
ShellCommandLineFreeVarList (Package);
}
+Exit:
SHELL_FREE_NON_NULL (FileName1);
SHELL_FREE_NON_NULL (FileName2);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c
index 7d7721d4ee..144007a3d3 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c
@@ -103,7 +103,7 @@ ShellCommandRunEdit (
TempParam = ShellCommandLineGetRawValue (Package, 1);
if (TempParam == NULL) {
ASSERT (TempParam != NULL);
- ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"edit");
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"edit");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
FileBufferSetFileName (TempParam);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c
index d2d642b194..ea190d0770 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c
@@ -48,6 +48,7 @@ ShellCommandRunEfiCompress (
InShellFileHandle = NULL;
OutShellFileHandle = NULL;
InBuffer = NULL;
+ Package = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
@@ -83,6 +84,7 @@ ShellCommandRunEfiCompress (
ASSERT (TempParam != NULL);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"eficompress");
ShellStatus = SHELL_INVALID_PARAMETER;
+ goto Exit;
}
InFileName = ShellFindFilePath (TempParam);
@@ -155,6 +157,11 @@ ShellCommandRunEfiCompress (
ShellCommandLineFreeVarList (Package);
}
+Exit:
+ if ((ShellStatus != SHELL_SUCCESS) && (Package != NULL)) {
+ ShellCommandLineFreeVarList (Package);
+ }
+
if (InShellFileHandle != NULL) {
gEfiShellProtocol->CloseFile (InShellFileHandle);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c
index af75d75036..37f19a156a 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c
@@ -89,7 +89,7 @@ ShellCommandRunEfiDecompress (
ASSERT (TempParam != NULL);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"efidecompress");
ShellStatus = SHELL_INVALID_PARAMETER;
- return (ShellStatus);
+ goto Done;
}
InFileName = ShellFindFilePath (TempParam);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c
index e33adc39f9..51e4ae2f81 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c
@@ -117,6 +117,8 @@ HMainCommandDisplayHelp (
);
if (InfoString != NULL) {
ShellPrintEx (0, CurrentLine+1, L"%E%s%N", InfoString);
+ } else {
+ ASSERT (FALSE);
}
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c
index 3fc635c254..40260ea3dc 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c
@@ -340,6 +340,7 @@ LoadEfiDriversFromRomImage (
FilePath = FileDevicePath (NULL, RomFileName);
if (FilePath == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_LOAD_FAIL), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex);
+ SHELL_FREE_NON_NULL (DecompressedImageBuffer);
return EFI_OUT_OF_RESOURCES;
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
index a061c97d07..3f4cada2b7 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
@@ -216,7 +216,8 @@ ShellCommandRunMemMap (
Descriptors = AllocateZeroPool (Size);
if (Descriptors == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"memmap");
- ShellStatus = SHELL_OUT_OF_RESOURCES;
+ ShellCommandLineFreeVarList (Package);
+ return SHELL_OUT_OF_RESOURCES;
}
Status = gBS->GetMemoryMap (&Size, Descriptors, &MapKey, &ItemSize, &Version);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c
index 807347200b..79c3aaafc4 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c
@@ -63,7 +63,7 @@ ShellCommandRunSetSize (
} else {
Temp1 = ShellCommandLineGetRawValue (Package, 1);
if (Temp1 == NULL) {
- ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize");
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setsize");
ShellStatus = SHELL_INVALID_PARAMETER;
NewSize = 0;
} else if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE)) {
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c
index 2f119b6ae6..9f8dee2bbe 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c
@@ -405,6 +405,7 @@ ShellCommandRunSetVar (
} else {
VariableName = ShellCommandLineGetRawValue (Package, 1);
if (VariableName == NULL) {
+ ShellCommandLineFreeVarList (Package);
return SHELL_INVALID_PARAMETER;
}
@@ -416,6 +417,7 @@ ShellCommandRunSetVar (
RStatus = StrToGuid (StringGuid, &Guid);
} else {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid);
+ ShellCommandLineFreeVarList (Package);
return SHELL_INVALID_PARAMETER;
}
@@ -434,6 +436,7 @@ ShellCommandRunSetVar (
Buffer = AllocateZeroPool (Size);
if (Buffer == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar");
+ ShellCommandLineFreeVarList (Package);
return SHELL_OUT_OF_RESOURCES;
}
@@ -460,6 +463,7 @@ ShellCommandRunSetVar (
Buffer = AllocateZeroPool (Size);
if (Buffer == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"setvar");
+ ShellCommandLineFreeVarList (Package);
return SHELL_OUT_OF_RESOURCES;
}
diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c
index 2204abacc1..0ff6a40c8c 100644
--- a/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c
+++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c
@@ -163,21 +163,24 @@ ShellCommandRunDisconnect (
Param1 = ShellCommandLineGetRawValue (Package, 1);
Param2 = ShellCommandLineGetRawValue (Package, 2);
Param3 = ShellCommandLineGetRawValue (Package, 3);
- if (Param1 != NULL) {
- ShellConvertStringToUint64 (Param1, &Intermediate1, TRUE, FALSE);
- }
- Handle1 = Param1 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate1) : NULL;
- if (Param2 != NULL) {
- ShellConvertStringToUint64 (Param2, &Intermediate2, TRUE, FALSE);
+ if (Param1 && !EFI_ERROR (ShellConvertStringToUint64 (Param1, &Intermediate1, TRUE, FALSE))) {
+ Handle1 = ConvertHandleIndexToHandle ((UINTN)Intermediate1);
+ } else {
+ Handle1 = NULL;
}
- Handle2 = Param2 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate2) : NULL;
- if (Param3 != NULL) {
- ShellConvertStringToUint64 (Param3, &Intermediate3, TRUE, FALSE);
+ if (Param2 && !EFI_ERROR (ShellConvertStringToUint64 (Param2, &Intermediate2, TRUE, FALSE))) {
+ Handle2 = ConvertHandleIndexToHandle ((UINTN)Intermediate2);
+ } else {
+ Handle2 = NULL;
}
- Handle3 = Param3 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate3) : NULL;
+ if (Param3 && !EFI_ERROR (ShellConvertStringToUint64 (Param3, &Intermediate3, TRUE, FALSE))) {
+ Handle3 = ConvertHandleIndexToHandle ((UINTN)Intermediate3);
+ } else {
+ Handle3 = NULL;
+ }
if ((Param1 != NULL) && (Handle1 == NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"disconnect", Param1);
diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c
index 158a3bb800..8b9f56972a 100644
--- a/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c
+++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c
@@ -250,6 +250,19 @@ ConfigToFile (
}
Status = HiiDatabase->ExportPackageLists (HiiDatabase, HiiHandle, &MainBufferSize, MainBuffer);
+ if (EFI_ERROR (Status)) {
+ SHELL_FREE_NON_NULL (MainBuffer);
+ ShellPrintHiiEx (
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_OUT_MEM),
+ gShellDriver1HiiHandle,
+ L"drvcfg"
+ );
+ ShellCloseFile (&FileHandle);
+ return (SHELL_DEVICE_ERROR);
+ }
}
Status = ShellWriteFile (FileHandle, &MainBufferSize, MainBuffer);
diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c
index 9235e7f40b..cb74983e28 100644
--- a/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c
+++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c
@@ -325,7 +325,6 @@ Done:
SHELL_FREE_NON_NULL (ChildHandleList);
SHELL_FREE_NON_NULL (Language);
SHELL_FREE_NON_NULL (OutBuffer);
- SHELL_FREE_NON_NULL (ErrorType);
return (Status2);
}
@@ -367,10 +366,9 @@ ShellCommandRunDrvDiag (
EFI_HANDLE Handle3;
UINT64 Intermediate;
- Intermediate = 0;
- ShellStatus = SHELL_SUCCESS;
- Mode = TestModeMax;
- Language = NULL;
+ ShellStatus = SHELL_SUCCESS;
+ Mode = TestModeMax;
+ Language = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c
index 262063c64e..0d3f901fea 100644
--- a/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c
+++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c
@@ -125,7 +125,7 @@ TraverseHandleDatabase (
OpenTypeString,
Name
);
- } else if (Name != NULL) {
+ } else {
ShellPrintHiiEx (
-1,
-1,
@@ -135,7 +135,7 @@ TraverseHandleDatabase (
HandleIndex,
OpenInfo[OpenInfoIndex].OpenCount,
OpenTypeString,
- Name
+ Name ? Name : L""
);
}
}
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
index cf01145717..993bcf7cb9 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
@@ -205,7 +205,8 @@ CopySingleFile (
DestVolumeInfo = AllocateZeroPool (DestVolumeInfoSize);
if (DestVolumeInfo == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"cp");
- return (SHELL_OUT_OF_RESOURCES);
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ goto Done;
}
Status = DestVolumeFP->GetInfo (
@@ -256,6 +257,7 @@ CopySingleFile (
SHELL_FREE_NON_NULL (DestVolumeInfo);
}
+Done:
//
// close files
//
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
index 8011e77461..acfd26cd10 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
@@ -74,6 +74,7 @@ PrintSfoVolumeInfoTableEntry (
if (Status == EFI_BUFFER_TOO_SMALL) {
SysInfo = AllocateZeroPool (SysInfoSize);
if (SysInfo == NULL) {
+ gEfiShellProtocol->CloseFile (ShellFileHandle);
return (EFI_OUT_OF_RESOURCES);
}
diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c
index 7f146bb9fb..076ad1e198 100644
--- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c
+++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c
@@ -308,7 +308,6 @@ ShellCommandRunHelp (
CONST CHAR16 *CurrentCommand;
CHAR16 *CommandToGetHelpOn;
CHAR16 *SectionToGetHelpOn;
- CHAR16 *HiiString;
BOOLEAN Found;
BOOLEAN PrintCommandText;
UINTN SortedCommandListSize;
@@ -398,9 +397,7 @@ ShellCommandRunHelp (
// we need info on the special characters
//
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HELP_SC_HEADER), gShellLevel3HiiHandle);
- HiiString = HiiGetString (gShellLevel3HiiHandle, STRING_TOKEN (STR_HELP_SC_DATA), NULL);
- ShellPrintEx (-1, -1, L"%s", HiiString);
- FreePool (HiiString);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HELP_SC_DATA), gShellLevel3HiiHandle);
Found = TRUE;
} else {
SortedCommandList = NULL;
diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
index 93e36197b2..f023505300 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
@@ -3820,7 +3820,10 @@ ShellPromptForResponseHii (
Prompt = HiiGetString (HiiFormatHandle, HiiFormatStringId, NULL);
Status = ShellPromptForResponse (Type, Prompt, Response);
- FreePool (Prompt);
+ if (Prompt != NULL) {
+ FreePool (Prompt);
+ }
+
return (Status);
}
diff --git a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ifconfig6.c b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ifconfig6.c
index 5cb92c485b..7e2326de8f 100644
--- a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ifconfig6.c
+++ b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ifconfig6.c
@@ -468,7 +468,10 @@ IfConfig6ParseManualAddressList (
}
AddrBuf = AllocateZeroPool (AddrCnt * sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS));
- ASSERT (AddrBuf != NULL);
+ if (AddrBuf == NULL) {
+ ASSERT (AddrBuf != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
AddrCnt = 0;
VarArg = *Arg;
@@ -569,7 +572,10 @@ IfConfig6ParseGwDnsAddressList (
}
AddrBuf = AllocateZeroPool (AddrCnt * sizeof (EFI_IPv6_ADDRESS));
- ASSERT (AddrBuf != NULL);
+ if (AddrBuf == NULL) {
+ ASSERT (AddrBuf != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
AddrCnt = 0;
VarArg = *Arg;
@@ -1194,7 +1200,7 @@ IfConfig6SetInterfaceInfo (
BOOLEAN IsAddressOk;
UINTN DataSize;
- UINT32 Index;
+ UINTN Index;
UINT32 Index2;
BOOLEAN IsAddressSet;
EFI_IP6_CONFIG_INTERFACE_INFO *IfInfo;