mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-25 06:34:30 +02:00
ShellPkg: UefiShellLevel2CommandsLib: 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>
This commit is contained in:
parent
040afc1e3b
commit
17ad30ae23
@ -304,8 +304,13 @@ ShellCommandRunCd (
|
|||||||
|
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
Param1Copy = PathCleanUpDirectories (Param1Copy);
|
Param1Copy = PathCleanUpDirectories (Param1Copy);
|
||||||
|
if (Param1Copy == NULL) {
|
||||||
|
Status = EFI_NOT_FOUND;
|
||||||
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
|
} else {
|
||||||
Status = ExtractDriveAndPath (Param1Copy, &Drive, &Path);
|
Status = ExtractDriveAndPath (Param1Copy, &Drive, &Path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!EFI_ERROR (Status) && (Drive != NULL) && (Path != NULL)) {
|
if (!EFI_ERROR (Status) && (Drive != NULL) && (Path != NULL)) {
|
||||||
if (EFI_ERROR (ShellIsDirectory (Param1Copy))) {
|
if (EFI_ERROR (ShellIsDirectory (Param1Copy))) {
|
||||||
|
@ -203,6 +203,11 @@ CopySingleFile (
|
|||||||
|
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
DestVolumeInfo = AllocateZeroPool (DestVolumeInfoSize);
|
DestVolumeInfo = AllocateZeroPool (DestVolumeInfoSize);
|
||||||
|
if (DestVolumeInfo == NULL) {
|
||||||
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"cp");
|
||||||
|
return (SHELL_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
|
|
||||||
Status = DestVolumeFP->GetInfo (
|
Status = DestVolumeFP->GetInfo (
|
||||||
DestVolumeFP,
|
DestVolumeFP,
|
||||||
&gEfiFileSystemInfoGuid,
|
&gEfiFileSystemInfoGuid,
|
||||||
|
@ -42,6 +42,9 @@ PrintSfoVolumeInfoTableEntry (
|
|||||||
|
|
||||||
if (Node->Handle == NULL) {
|
if (Node->Handle == NULL) {
|
||||||
DirectoryName = GetFullyQualifiedPath (((EFI_SHELL_FILE_INFO *)GetFirstNode (&TheList->Link))->FullName);
|
DirectoryName = GetFullyQualifiedPath (((EFI_SHELL_FILE_INFO *)GetFirstNode (&TheList->Link))->FullName);
|
||||||
|
if (DirectoryName == NULL) {
|
||||||
|
return (EFI_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We need to open something up to get system information
|
// We need to open something up to get system information
|
||||||
@ -70,6 +73,10 @@ PrintSfoVolumeInfoTableEntry (
|
|||||||
|
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
SysInfo = AllocateZeroPool (SysInfoSize);
|
SysInfo = AllocateZeroPool (SysInfoSize);
|
||||||
|
if (SysInfo == NULL) {
|
||||||
|
return (EFI_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
|
|
||||||
Status = EfiFpHandle->GetInfo (
|
Status = EfiFpHandle->GetInfo (
|
||||||
EfiFpHandle,
|
EfiFpHandle,
|
||||||
&gEfiFileSystemInfoGuid,
|
&gEfiFileSystemInfoGuid,
|
||||||
@ -97,6 +104,10 @@ PrintSfoVolumeInfoTableEntry (
|
|||||||
|
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
SysInfo = AllocateZeroPool (SysInfoSize);
|
SysInfo = AllocateZeroPool (SysInfoSize);
|
||||||
|
if (SysInfo == NULL) {
|
||||||
|
return (EFI_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
|
|
||||||
Status = EfiFpHandle->GetInfo (
|
Status = EfiFpHandle->GetInfo (
|
||||||
EfiFpHandle,
|
EfiFpHandle,
|
||||||
&gEfiFileSystemInfoGuid,
|
&gEfiFileSystemInfoGuid,
|
||||||
@ -616,6 +627,10 @@ PrintLsOutput (
|
|||||||
}
|
}
|
||||||
|
|
||||||
CorrectedPath = StrnCatGrow (&CorrectedPath, &LongestPath, L"*", 0);
|
CorrectedPath = StrnCatGrow (&CorrectedPath, &LongestPath, L"*", 0);
|
||||||
|
if (CorrectedPath == NULL) {
|
||||||
|
return SHELL_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
Status = ShellOpenFileMetaArg ((CHAR16 *)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
|
Status = ShellOpenFileMetaArg ((CHAR16 *)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
|
||||||
|
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
|
@ -82,7 +82,11 @@ SearchList (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
TempList = StrnCatGrow (&TempList, NULL, ListWalker, 0);
|
TempList = StrnCatGrow (&TempList, NULL, ListWalker, 0);
|
||||||
|
if (TempList == NULL) {
|
||||||
ASSERT (TempList != NULL);
|
ASSERT (TempList != NULL);
|
||||||
|
return (FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
TempSpot = StrStr (TempList, Target);
|
TempSpot = StrStr (TempList, Target);
|
||||||
if (TempSpot != NULL) {
|
if (TempSpot != NULL) {
|
||||||
*TempSpot = CHAR_NULL;
|
*TempSpot = CHAR_NULL;
|
||||||
|
@ -315,7 +315,11 @@ ShellCommandRunParse (
|
|||||||
ShellCommandInstance = ShellStrToUintn (ShellCommandLineGetValue (Package, L"-s"));
|
ShellCommandInstance = ShellStrToUintn (ShellCommandLineGetValue (Package, L"-s"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((FileName != NULL) && (TableName != NULL) && (ColumnString != NULL)) {
|
||||||
ShellStatus = PerformParsing (FileName, TableName, ShellStrToUintn (ColumnString), TableNameInstance, ShellCommandInstance, StreamingUnicode);
|
ShellStatus = PerformParsing (FileName, TableName, ShellStrToUintn (ColumnString), TableNameInstance, ShellCommandInstance, StreamingUnicode);
|
||||||
|
} else {
|
||||||
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ IsValidDeleteTarget (
|
|||||||
}
|
}
|
||||||
|
|
||||||
TempLocation = StrStr (Node->FullName, L":");
|
TempLocation = StrStr (Node->FullName, L":");
|
||||||
if (StrLen (TempLocation) <= 2) {
|
if ((TempLocation == NULL) || (StrLen (TempLocation) <= 2)) {
|
||||||
//
|
//
|
||||||
// Deleting the root directory is invalid.
|
// Deleting the root directory is invalid.
|
||||||
//
|
//
|
||||||
@ -242,6 +242,11 @@ IsValidDeleteTarget (
|
|||||||
Pattern = StrnCatGrow (&Pattern, &Size, L"\\", 0);
|
Pattern = StrnCatGrow (&Pattern, &Size, L"\\", 0);
|
||||||
Size = 0;
|
Size = 0;
|
||||||
SearchString = StrnCatGrow (&SearchString, &Size, Node->FullName, 0);
|
SearchString = StrnCatGrow (&SearchString, &Size, Node->FullName, 0);
|
||||||
|
if (SearchString == NULL) {
|
||||||
|
RetVal = FALSE;
|
||||||
|
goto Done;
|
||||||
|
}
|
||||||
|
|
||||||
if (!EFI_ERROR (ShellIsDirectory (SearchString))) {
|
if (!EFI_ERROR (ShellIsDirectory (SearchString))) {
|
||||||
SearchString = StrnCatGrow (&SearchString, &Size, L"\\", 0);
|
SearchString = StrnCatGrow (&SearchString, &Size, L"\\", 0);
|
||||||
SearchString = StrnCatGrow (&SearchString, &Size, L"*", 0);
|
SearchString = StrnCatGrow (&SearchString, &Size, L"*", 0);
|
||||||
@ -256,6 +261,7 @@ IsValidDeleteTarget (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Done:
|
||||||
SHELL_FREE_NON_NULL (Pattern);
|
SHELL_FREE_NON_NULL (Pattern);
|
||||||
SHELL_FREE_NON_NULL (SearchString);
|
SHELL_FREE_NON_NULL (SearchString);
|
||||||
|
|
||||||
|
@ -88,6 +88,12 @@ HandleVol (
|
|||||||
|
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
SysInfo = AllocateZeroPool (SysInfoSize);
|
SysInfo = AllocateZeroPool (SysInfoSize);
|
||||||
|
if (SysInfo == NULL) {
|
||||||
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"vol");
|
||||||
|
ASSERT (FALSE);
|
||||||
|
return SHELL_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
Status = EfiFpHandle->GetInfo (
|
Status = EfiFpHandle->GetInfo (
|
||||||
EfiFpHandle,
|
EfiFpHandle,
|
||||||
&gEfiFileSystemInfoGuid,
|
&gEfiFileSystemInfoGuid,
|
||||||
@ -96,8 +102,6 @@ HandleVol (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT (SysInfo != NULL);
|
|
||||||
|
|
||||||
if (Delete) {
|
if (Delete) {
|
||||||
*((CHAR16 *)SysInfo->VolumeLabel) = CHAR_NULL;
|
*((CHAR16 *)SysInfo->VolumeLabel) = CHAR_NULL;
|
||||||
SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (SysInfo->VolumeLabel);
|
SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (SysInfo->VolumeLabel);
|
||||||
@ -155,6 +159,11 @@ HandleVol (
|
|||||||
|
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
SysInfo = AllocateZeroPool (SysInfoSize);
|
SysInfo = AllocateZeroPool (SysInfoSize);
|
||||||
|
if (SysInfo == NULL) {
|
||||||
|
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"vol");
|
||||||
|
return SHELL_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
Status = EfiFpHandle->GetInfo (
|
Status = EfiFpHandle->GetInfo (
|
||||||
EfiFpHandle,
|
EfiFpHandle,
|
||||||
&gEfiFileSystemInfoGuid,
|
&gEfiFileSystemInfoGuid,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user