Skip to content

Commit

Permalink
ShellPkg: Additional CodeQL fixes (#268)
Browse files Browse the repository at this point in the history
Various fixes

- [x] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [x] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

Build ShellPkg and boot changes on QemuQ35Pkg to EFI shell.

N/A
  • Loading branch information
TaylorBeebe authored and kenlautner committed Oct 17, 2023
1 parent 5269098 commit cb70eb0
Show file tree
Hide file tree
Showing 41 changed files with 706 additions and 184 deletions.
3 changes: 3 additions & 0 deletions CodeQlFilters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"-MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c:SM02311",
"-MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c:SM02311",
"-MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c:SM02311",
"-ShellPkg/Library/UefiShellLevel3CommandsLib/Alias.c:SM02311",
"-ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c:SM02311",
"-ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c:SM02311",
"-MdeModulePkg/Universal/Disk/UdfDxe/FileName.c:cpp/uselesstest",
"-MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c:cpp/uselesstest",
"-MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c:cpp/uselesstest",
Expand Down
6 changes: 3 additions & 3 deletions MdePkg/Include/IndustryStandard/PciExpress21.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,9 @@ typedef struct {
UINT16 DpaControl;
UINT8 DpaPowerAllocationArray[1];
} PCI_EXPRESS_EXTENDED_CAPABILITIES_DYNAMIC_POWER_ALLOCATION;

#define PCI_EXPRESS_EXTENDED_CAPABILITY_DYNAMIC_POWER_ALLOCATION_GET_SUBSTATE_MAX(POWER) (UINT16)(((POWER->DpaCapability)&0x0000000F))

// MU_CHANGE [START] - CodeQL change
#define PCI_EXPRESS_EXTENDED_CAPABILITY_DYNAMIC_POWER_ALLOCATION_GET_SUBSTATE_MAX(POWER) (UINT32)(((POWER->DpaCapability)&0x0000000F))
// MU_CHANGE [END] - CodeQL change
#define PCI_EXPRESS_EXTENDED_CAPABILITY_LATENCE_TOLERANCE_REPORTING_ID 0x0018
#define PCI_EXPRESS_EXTENDED_CAPABILITY_LATENCE_TOLERANCE_REPORTING_VER1 0x1

Expand Down
27 changes: 20 additions & 7 deletions ShellPkg/Application/Shell/Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,9 @@ DoStartupScript (
}

Status = RunShellCommand (FileStringPath, &CalleeStatus);
if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit == TRUE) {
// MU_CHANGE [START] - CodeQL change
if ((!EFI_ERROR (Status)) && (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit == TRUE)) {
// MU_CHANGE [END] - CodeQL change
ShellCommandRegisterExit (gEfiShellProtocol->BatchIsActive (), (UINT64)CalleeStatus);
}

Expand Down Expand Up @@ -2608,11 +2610,19 @@ RunCommandOrFile (
CommandWithPath = ShellFindFilePathEx (FirstParameter, mExecutableExtensions);
}

//
// This should be impossible now.
//
ASSERT (CommandWithPath != NULL);
// MU_CHANGE [START] - CodeQL change
if (CommandWithPath == NULL) {
//
// This should be impossible now.
//
ASSERT (CommandWithPath != NULL);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
SetLastError (SHELL_NOT_FOUND);
SHELL_FREE_NON_NULL (CommandWithPath);
return EFI_NOT_FOUND;
}

// MU_CHANGE [END] - CodeQL change
//
// Make sure that path is not just a directory (or not found)
//
Expand Down Expand Up @@ -3329,8 +3339,11 @@ FindFirstCharacter (
IN CONST CHAR16 EscapeCharacter
)
{
UINT32 WalkChar;
UINT32 WalkStr;
// MU_CHANGE [START] - CodeQL change
UINTN WalkChar;
UINTN WalkStr;

// MU_CHANGE [END] - CodeQL change

for (WalkStr = 0; WalkStr < StrLen (String); WalkStr++) {
if (String[WalkStr] == EscapeCharacter) {
Expand Down
29 changes: 25 additions & 4 deletions ShellPkg/Application/Shell/ShellManParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,14 @@ ProcessManFile (
TempString = ShellCommandGetCommandHelp (Command);
if (TempString != NULL) {
FileHandle = ConvertEfiFileProtocolToShellHandle (CreateFileInterfaceMem (TRUE), NULL);
HelpSize = StrLen (TempString) * sizeof (CHAR16);
// MU_CHANGE [START] - CodeQL change
if (FileHandle == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}

// MU_CHANGE [END] - CodeQL change
HelpSize = StrLen (TempString) * sizeof (CHAR16);
ShellWriteFile (FileHandle, &HelpSize, TempString);
ShellSetFilePosition (FileHandle, 0);
HelpSize = 0;
Expand All @@ -624,8 +631,15 @@ ProcessManFile (
Status = SearchPathForFile (TempString, &FileHandle);
if (EFI_ERROR (Status)) {
FileDevPath = FileDevicePath (NULL, TempString);
DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, FileDevPath);
Status = InternalOpenFileDevicePath (DevPath, &FileHandle, EFI_FILE_MODE_READ, 0);
// MU_CHANGE [START] - CodeQL change
if (FileDevPath == NULL) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}

// MU_CHANGE [END] - CodeQL change
DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, FileDevPath);
Status = InternalOpenFileDevicePath (DevPath, &FileHandle, EFI_FILE_MODE_READ, 0);
SHELL_FREE_NON_NULL (FileDevPath);
SHELL_FREE_NON_NULL (DevPath);
}
Expand Down Expand Up @@ -733,7 +747,14 @@ ProcessManFile (
}

FileHandle = ConvertEfiFileProtocolToShellHandle (CreateFileInterfaceMem (TRUE), NULL);
HelpSize = StrLen (TempString) * sizeof (CHAR16);
// MU_CHANGE [START] - CodeQL change
if (FileHandle == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}

// MU_CHANGE [END] - CodeQL change
HelpSize = StrLen (TempString) * sizeof (CHAR16);
ShellWriteFile (FileHandle, &HelpSize, TempString);
ShellSetFilePosition (FileHandle, 0);
HelpSize = 0;
Expand Down
6 changes: 6 additions & 0 deletions ShellPkg/Application/Shell/ShellParametersProtocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,12 @@ UpdateStdInStdOutStdErr (
TempHandle = CreateFileInterfaceFile (TempHandle, FALSE);
}

// MU_CHANGE [START] - CodeQL change
if (TempHandle == NULL) {
return EFI_OUT_OF_RESOURCES;
}

// MU_CHANGE [END] - CodeQL change
ShellParameters->StdIn = TempHandle;
gST->ConIn = CreateSimpleTextInOnFile (TempHandle, &gST->ConsoleInHandle);
}
Expand Down
Loading

0 comments on commit cb70eb0

Please sign in to comment.