diff options
| author | Oliver Smith-Denny <osde@microsoft.com> | 2024-10-03 20:30:15 +0300 |
|---|---|---|
| committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-10-29 05:09:18 +0300 |
| commit | 875202bf85d528fb7c63c4827cfe013b58f2870f (patch) | |
| tree | a2e05932127efc01c9715186514644415cb1590f /ShellPkg/Application/Shell/ShellParametersProtocol.c | |
| parent | c69e5e647d69fcbb6d2a4e5da82e72122d41566f (diff) | |
| download | edk2-875202bf85d528fb7c63c4827cfe013b58f2870f.tar.xz | |
ShellPkg: Shell: 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/Application/Shell/ShellParametersProtocol.c')
| -rw-r--r-- | ShellPkg/Application/Shell/ShellParametersProtocol.c | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c index 64d67d9f13..8464cbf616 100644 --- a/ShellPkg/Application/Shell/ShellParametersProtocol.c +++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c @@ -354,7 +354,11 @@ CreatePopulateInstallShellParametersProtocol ( Status = SHELL_GET_ENVIRONMENT_VARIABLE (L"ShellOpt", &Size, FullCommandLine);
if (Status == EFI_BUFFER_TOO_SMALL) {
FullCommandLine = AllocateZeroPool (Size + LoadedImage->LoadOptionsSize);
- Status = SHELL_GET_ENVIRONMENT_VARIABLE (L"ShellOpt", &Size, FullCommandLine);
+ if (FullCommandLine == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = SHELL_GET_ENVIRONMENT_VARIABLE (L"ShellOpt", &Size, FullCommandLine);
}
if (Status == EFI_NOT_FOUND) {
@@ -738,6 +742,7 @@ UpdateStdInStdOutStdErr ( OutAppend = FALSE;
CommandLineCopy = NULL;
FirstLocation = NULL;
+ TempHandle = NULL;
if ((ShellParameters == NULL) || (SystemTableInfo == NULL) || (OldStdIn == NULL) || (OldStdOut == NULL) || (OldStdErr == NULL)) {
return (EFI_INVALID_PARAMETER);
@@ -1176,7 +1181,10 @@ UpdateStdInStdOutStdErr ( if (!ErrUnicode && !EFI_ERROR (Status)) {
TempHandle = CreateFileInterfaceFile (TempHandle, FALSE);
- ASSERT (TempHandle != NULL);
+ if (TempHandle == NULL) {
+ ASSERT (TempHandle != NULL);
+ Status = EFI_OUT_OF_RESOURCES;
+ }
}
if (!EFI_ERROR (Status)) {
@@ -1223,7 +1231,10 @@ UpdateStdInStdOutStdErr ( if (!OutUnicode && !EFI_ERROR (Status)) {
TempHandle = CreateFileInterfaceFile (TempHandle, FALSE);
- ASSERT (TempHandle != NULL);
+ if (TempHandle == NULL) {
+ ASSERT (TempHandle != NULL);
+ Status = EFI_OUT_OF_RESOURCES;
+ }
}
if (!EFI_ERROR (Status)) {
@@ -1245,9 +1256,13 @@ UpdateStdInStdOutStdErr ( }
TempHandle = CreateFileInterfaceEnv (StdOutVarName);
- ASSERT (TempHandle != NULL);
- ShellParameters->StdOut = TempHandle;
- gST->ConOut = CreateSimpleTextOutOnFile (TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
+ if (TempHandle == NULL) {
+ ASSERT (TempHandle != NULL);
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ ShellParameters->StdOut = TempHandle;
+ gST->ConOut = CreateSimpleTextOutOnFile (TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
+ }
}
//
@@ -1262,9 +1277,13 @@ UpdateStdInStdOutStdErr ( }
TempHandle = CreateFileInterfaceEnv (StdErrVarName);
- ASSERT (TempHandle != NULL);
- ShellParameters->StdErr = TempHandle;
- gST->StdErr = CreateSimpleTextOutOnFile (TempHandle, &gST->StandardErrorHandle, gST->StdErr);
+ if (TempHandle == NULL) {
+ ASSERT (TempHandle != NULL);
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ ShellParameters->StdErr = TempHandle;
+ gST->StdErr = CreateSimpleTextOutOnFile (TempHandle, &gST->StandardErrorHandle, gST->StdErr);
+ }
}
//
@@ -1307,8 +1326,12 @@ UpdateStdInStdOutStdErr ( TempHandle = CreateFileInterfaceFile (TempHandle, FALSE);
}
- ShellParameters->StdIn = TempHandle;
- gST->ConIn = CreateSimpleTextInOnFile (TempHandle, &gST->ConsoleInHandle);
+ if (TempHandle == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ ShellParameters->StdIn = TempHandle;
+ gST->ConIn = CreateSimpleTextInOnFile (TempHandle, &gST->ConsoleInHandle);
+ }
}
}
}
|
