diff options
author | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2010-10-04 16:24:30 +0000 |
---|---|---|
committer | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2010-10-04 16:24:30 +0000 |
commit | 3c865f2064d37eaccd1693b878596d5138b0b38e (patch) | |
tree | ffe10112e71c18c5c4ec56f37cc670258b22fd5b /ShellPkg | |
parent | aca84419c4b5128b69215b8f6e4d34c36efb1fbc (diff) | |
download | edk2-platforms-3c865f2064d37eaccd1693b878596d5138b0b38e.tar.xz |
1) Removing ASSERTs for proper return values.
2) Verifying that memory allocations were successful.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10904 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg')
-rw-r--r-- | ShellPkg/Application/Shell/ConsoleLogger.c | 6 | ||||
-rw-r--r-- | ShellPkg/Application/Shell/FileHandleWrappers.c | 5 | ||||
-rw-r--r-- | ShellPkg/Application/Shell/Shell.c | 368 | ||||
-rw-r--r-- | ShellPkg/Application/Shell/ShellEnvVar.c | 31 | ||||
-rw-r--r-- | ShellPkg/Application/Shell/ShellManParser.c | 14 | ||||
-rw-r--r-- | ShellPkg/Application/Shell/ShellParametersProtocol.c | 64 | ||||
-rw-r--r-- | ShellPkg/Application/Shell/ShellProtocol.c | 24 |
7 files changed, 307 insertions, 205 deletions
diff --git a/ShellPkg/Application/Shell/ConsoleLogger.c b/ShellPkg/Application/Shell/ConsoleLogger.c index 4b0d94d245..2b84d87adb 100644 --- a/ShellPkg/Application/Shell/ConsoleLogger.c +++ b/ShellPkg/Application/Shell/ConsoleLogger.c @@ -39,8 +39,10 @@ ConsoleLoggerInstall( EFI_STATUS Status;
ASSERT(ConsoleInfo != NULL);
- *ConsoleInfo = AllocatePool(sizeof(CONSOLE_LOGGER_PRIVATE_DATA));
- ASSERT(ConsoleInfo != NULL);
+ (*ConsoleInfo) = AllocatePool(sizeof(CONSOLE_LOGGER_PRIVATE_DATA));
+ if ((*ConsoleInfo) == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
(*ConsoleInfo)->Signature = CONSOLE_LOGGER_PRIVATE_DATA_SIGNATURE;
(*ConsoleInfo)->OldConOut = NULL;
diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c index 02e42e3c9d..ee13d0cb73 100644 --- a/ShellPkg/Application/Shell/FileHandleWrappers.c +++ b/ShellPkg/Application/Shell/FileHandleWrappers.c @@ -1406,7 +1406,7 @@ FileInterfaceMemClose( )
{
SHELL_FREE_NON_NULL(((EFI_FILE_PROTOCOL_MEM*)This)->Buffer);
- SHELL_FREE_NON_NULL((EFI_FILE_PROTOCOL_MEM*)This);
+ SHELL_FREE_NON_NULL(This);
return (EFI_SUCCESS);
}
@@ -1553,6 +1553,9 @@ CreateFileInterfaceFile( EFI_FILE_PROTOCOL_FILE *NewOne;
NewOne = AllocatePool(sizeof(EFI_FILE_PROTOCOL_FILE));
+ if (NewOne == NULL) {
+ return (NULL);
+ }
CopyMem(NewOne, Template, sizeof(EFI_FILE_PROTOCOL_FILE));
NewOne->Orig = (EFI_FILE_PROTOCOL *)Template;
NewOne->Unicode = Unicode;
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index 3401bc0644..ddd5d1712a 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -56,6 +56,7 @@ SHELL_INFO ShellInfoObject = { STATIC CONST CHAR16 mScriptExtension[] = L".NSH";
STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI";
+STATIC CONST CHAR16 mStartupScript[] = L"startup.nsh";
/**
The entry point for the application.
@@ -94,7 +95,9 @@ UefiMain ( // Clear the screen
//
Status = gST->ConOut->ClearScreen(gST->ConOut);
- ASSERT_EFI_ERROR(Status);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
//
// Populate the global structure from PCDs
@@ -136,178 +139,179 @@ UefiMain ( // install our console logger. This will keep a log of the output for back-browsing
//
Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo);
- ASSERT_EFI_ERROR(Status);
-
- //
- // Enable the cursor to be visible
- //
- gST->ConOut->EnableCursor (gST->ConOut, TRUE);
+ if (!EFI_ERROR(Status)) {
+ //
+ // Enable the cursor to be visible
+ //
+ gST->ConOut->EnableCursor (gST->ConOut, TRUE);
- //
- // If supporting EFI 1.1 we need to install HII protocol
- // only do this if PcdShellRequireHiiPlatform == FALSE
- //
- // remove EFI_UNSUPPORTED check above when complete.
- ///@todo add support for Framework HII
+ //
+ // If supporting EFI 1.1 we need to install HII protocol
+ // only do this if PcdShellRequireHiiPlatform == FALSE
+ //
+ // remove EFI_UNSUPPORTED check above when complete.
+ ///@todo add support for Framework HII
- //
- // install our (solitary) HII package
- //
- ShellInfoObject.HiiHandle = HiiAddPackages (&gEfiCallerIdGuid, gImageHandle, ShellStrings, NULL);
- if (ShellInfoObject.HiiHandle == NULL) {
- if (PcdGetBool(PcdShellSupportFrameworkHii)) {
- ///@todo Add our package into Framework HII
- }
+ //
+ // install our (solitary) HII package
+ //
+ ShellInfoObject.HiiHandle = HiiAddPackages (&gEfiCallerIdGuid, gImageHandle, ShellStrings, NULL);
if (ShellInfoObject.HiiHandle == NULL) {
- return (EFI_NOT_STARTED);
+ if (PcdGetBool(PcdShellSupportFrameworkHii)) {
+ ///@todo Add our package into Framework HII
+ }
+ if (ShellInfoObject.HiiHandle == NULL) {
+ return (EFI_NOT_STARTED);
+ }
}
- }
- //
- // create and install the EfiShellParametersProtocol
- //
- Status = CreatePopulateInstallShellParametersProtocol(&ShellInfoObject.NewShellParametersProtocol, &ShellInfoObject.RootShellInstance);
- ASSERT_EFI_ERROR(Status);
- ASSERT(ShellInfoObject.NewShellParametersProtocol != NULL);
-
- //
- // create and install the EfiShellProtocol
- //
- Status = CreatePopulateInstallShellProtocol(&ShellInfoObject.NewEfiShellProtocol);
- ASSERT_EFI_ERROR(Status);
- ASSERT(ShellInfoObject.NewEfiShellProtocol != NULL);
-
- //
- // Now initialize the shell library (it requires Shell Parameters protocol)
- //
- Status = ShellInitialize();
- ASSERT_EFI_ERROR(Status);
+ //
+ // create and install the EfiShellParametersProtocol
+ //
+ Status = CreatePopulateInstallShellParametersProtocol(&ShellInfoObject.NewShellParametersProtocol, &ShellInfoObject.RootShellInstance);
+ ASSERT_EFI_ERROR(Status);
+ ASSERT(ShellInfoObject.NewShellParametersProtocol != NULL);
- Status = CommandInit();
- ASSERT_EFI_ERROR(Status);
+ //
+ // create and install the EfiShellProtocol
+ //
+ Status = CreatePopulateInstallShellProtocol(&ShellInfoObject.NewEfiShellProtocol);
+ ASSERT_EFI_ERROR(Status);
+ ASSERT(ShellInfoObject.NewEfiShellProtocol != NULL);
- //
- // Check the command line
- //
- Status = ProcessCommandLine();
+ //
+ // Now initialize the shell library (it requires Shell Parameters protocol)
+ //
+ Status = ShellInitialize();
+ ASSERT_EFI_ERROR(Status);
- //
- // If shell support level is >= 1 create the mappings and paths
- //
- if (PcdGet8(PcdShellSupportLevel) >= 1) {
- Status = ShellCommandCreateInitialMappingsAndPaths();
- }
+ Status = CommandInit();
+ ASSERT_EFI_ERROR(Status);
- //
- // save the device path for the loaded image and the device path for the filepath (under loaded image)
- // These are where to look for the startup.nsh file
- //
- Status = GetDevicePathsForImageAndFile(&ShellInfoObject.ImageDevPath, &ShellInfoObject.FileDevPath);
- ASSERT_EFI_ERROR(Status);
+ //
+ // Check the command line
+ //
+ Status = ProcessCommandLine();
- //
- // Display the version
- //
- if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion) {
- ShellPrintHiiEx (
- 0,
- gST->ConOut->Mode->CursorRow,
- NULL,
- STRING_TOKEN (STR_VER_OUTPUT_MAIN),
- ShellInfoObject.HiiHandle,
- SupportLevel[PcdGet8(PcdShellSupportLevel)],
- gEfiShellProtocol->MajorVersion,
- gEfiShellProtocol->MinorVersion,
- (gST->Hdr.Revision&0xffff0000)>>16,
- (gST->Hdr.Revision&0x0000ffff),
- gST->FirmwareVendor,
- gST->FirmwareRevision
- );
- }
+ //
+ // If shell support level is >= 1 create the mappings and paths
+ //
+ if (PcdGet8(PcdShellSupportLevel) >= 1) {
+ Status = ShellCommandCreateInitialMappingsAndPaths();
+ }
- //
- // Display the mapping
- //
- if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {
- Status = RunCommand(L"map");
+ //
+ // save the device path for the loaded image and the device path for the filepath (under loaded image)
+ // These are where to look for the startup.nsh file
+ //
+ Status = GetDevicePathsForImageAndFile(&ShellInfoObject.ImageDevPath, &ShellInfoObject.FileDevPath);
ASSERT_EFI_ERROR(Status);
- }
- //
- // init all the built in alias'
- //
- Status = SetBuiltInAlias();
- ASSERT_EFI_ERROR(Status);
-
- //
- // Initialize environment variables
- //
- if (ShellCommandGetProfileList() != NULL) {
- Status = InternalEfiShellSetEnv(L"profiles", ShellCommandGetProfileList(), TRUE);
- ASSERT_EFI_ERROR(Status);
- }
+ //
+ // Display the version
+ //
+ if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion) {
+ ShellPrintHiiEx (
+ 0,
+ gST->ConOut->Mode->CursorRow,
+ NULL,
+ STRING_TOKEN (STR_VER_OUTPUT_MAIN),
+ ShellInfoObject.HiiHandle,
+ SupportLevel[PcdGet8(PcdShellSupportLevel)],
+ gEfiShellProtocol->MajorVersion,
+ gEfiShellProtocol->MinorVersion,
+ (gST->Hdr.Revision&0xffff0000)>>16,
+ (gST->Hdr.Revision&0x0000ffff),
+ gST->FirmwareVendor,
+ gST->FirmwareRevision
+ );
+ }
- Size = 100;
- TempString = AllocateZeroPool(Size);
+ //
+ // Display the mapping
+ //
+ if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {
+ Status = RunCommand(L"map");
+ ASSERT_EFI_ERROR(Status);
+ }
- UnicodeSPrint(TempString, Size, L"%d", PcdGet8(PcdShellSupportLevel));
- Status = InternalEfiShellSetEnv(L"uefishellsupport", TempString, TRUE);
- ASSERT_EFI_ERROR(Status);
+ //
+ // init all the built in alias'
+ //
+ Status = SetBuiltInAlias();
+ ASSERT_EFI_ERROR(Status);
- UnicodeSPrint(TempString, Size, L"%d.%d", ShellInfoObject.NewEfiShellProtocol->MajorVersion, ShellInfoObject.NewEfiShellProtocol->MinorVersion);
- Status = InternalEfiShellSetEnv(L"uefishellversion", TempString, TRUE);
- ASSERT_EFI_ERROR(Status);
+ //
+ // Initialize environment variables
+ //
+ if (ShellCommandGetProfileList() != NULL) {
+ Status = InternalEfiShellSetEnv(L"profiles", ShellCommandGetProfileList(), TRUE);
+ ASSERT_EFI_ERROR(Status);
+ }
- UnicodeSPrint(TempString, Size, L"%d.%d", (gST->Hdr.Revision & 0xFFFF0000) >> 16, gST->Hdr.Revision & 0x0000FFFF);
- Status = InternalEfiShellSetEnv(L"uefiversion", TempString, TRUE);
- ASSERT_EFI_ERROR(Status);
+ Size = 100;
+ TempString = AllocateZeroPool(Size);
- FreePool(TempString);
+ UnicodeSPrint(TempString, Size, L"%d", PcdGet8(PcdShellSupportLevel));
+ Status = InternalEfiShellSetEnv(L"uefishellsupport", TempString, TRUE);
+ ASSERT_EFI_ERROR(Status);
- if (!EFI_ERROR(Status)) {
- if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {
- //
- // Set up the event for CTRL-C monitoring...
- //
+ UnicodeSPrint(TempString, Size, L"%d.%d", ShellInfoObject.NewEfiShellProtocol->MajorVersion, ShellInfoObject.NewEfiShellProtocol->MinorVersion);
+ Status = InternalEfiShellSetEnv(L"uefishellversion", TempString, TRUE);
+ ASSERT_EFI_ERROR(Status);
- ///@todo add support for using SimpleInputEx here
- // if SimpleInputEx is not available display a warning.
- }
+ UnicodeSPrint(TempString, Size, L"%d.%d", (gST->Hdr.Revision & 0xFFFF0000) >> 16, gST->Hdr.Revision & 0x0000FFFF);
+ Status = InternalEfiShellSetEnv(L"uefiversion", TempString, TRUE);
+ ASSERT_EFI_ERROR(Status);
- if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) {
- //
- // process the startup script or launch the called app.
- //
- Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);
- }
+ FreePool(TempString);
- if ((PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {
- //
- // begin the UI waiting loop
- //
- do {
+ if (!EFI_ERROR(Status)) {
+ if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {
//
- // clean out all the memory allocated for CONST <something> * return values
- // between each shell prompt presentation
+ // Set up the event for CTRL-C monitoring...
//
- if (!IsListEmpty(&ShellInfoObject.BufferToFreeList.Link)){
- FreeBufferList(&ShellInfoObject.BufferToFreeList);
- }
+ ///@todo add support for using SimpleInputEx here
+ // if SimpleInputEx is not available display a warning.
+ }
+
+ if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) {
//
- // Reset page break back to default.
+ // process the startup script or launch the called app.
//
- ShellInfoObject.PageBreakEnabled = PcdGetBool(PcdShellPageBreakDefault);
- ShellInfoObject.ConsoleInfo->Enabled = TRUE;
- ShellInfoObject.ConsoleInfo->RowCounter = 0;
+ Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);
+ }
+ if ((PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {
//
- // Display Prompt
+ // begin the UI waiting loop
//
- Status = DoShellPrompt();
- } while (!ShellCommandGetExit());
+ do {
+ //
+ // clean out all the memory allocated for CONST <something> * return values
+ // between each shell prompt presentation
+ //
+ if (!IsListEmpty(&ShellInfoObject.BufferToFreeList.Link)){
+ FreeBufferList(&ShellInfoObject.BufferToFreeList);
+ }
+
+ //
+ // Reset page break back to default.
+ //
+ ShellInfoObject.PageBreakEnabled = PcdGetBool(PcdShellPageBreakDefault);
+ ShellInfoObject.ConsoleInfo->Enabled = TRUE;
+ ShellInfoObject.ConsoleInfo->RowCounter = 0;
+
+ //
+ // Display Prompt
+ //
+ Status = DoShellPrompt();
+ } while (!ShellCommandGetExit());
+ }
}
}
+
//
// uninstall protocols / free memory / etc...
//
@@ -342,7 +346,7 @@ UefiMain ( }
if (!IsListEmpty(&ShellInfoObject.SplitList.Link)){
- ASSERT(FALSE);
+ ASSERT(FALSE); ///@todo finish this de-allocation.
}
if (ShellInfoObject.ShellInitSettings.FileName != NULL) {
@@ -579,6 +583,9 @@ ProcessCommandLine( TempConst = ShellCommandLineGetRawValue(Package, Count++);
if (TempConst != NULL && StrLen(TempConst)) {
ShellInfoObject.ShellInitSettings.FileName = AllocatePool(StrSize(TempConst));
+ if (ShellInfoObject.ShellInitSettings.FileName == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
StrCpy(ShellInfoObject.ShellInitSettings.FileName, TempConst);
ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = 1;
for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
@@ -593,10 +600,18 @@ ProcessCommandLine( &Size,
L" ",
0);
+ if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {
+ SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);
+ return (EFI_OUT_OF_RESOURCES);
+ }
StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,
&Size,
gEfiShellParametersProtocol->Argv[LoopVar],
0);
+ if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {
+ SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);
+ return (EFI_OUT_OF_RESOURCES);
+ }
}
}
}
@@ -676,9 +691,12 @@ DoStartupScript( NewSize += StrSize(ShellInfoObject.ShellInitSettings.FileOptions) + sizeof(CHAR16);
}
FileStringPath = AllocateZeroPool(NewSize);
+ if (FileStringPath == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
StrCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName);
if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {
- StrCat (FileStringPath, L" ");
+ StrCat(FileStringPath, L" ");
StrCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions);
}
Status = RunCommand(FileStringPath);
@@ -717,7 +735,7 @@ DoStartupScript( return (EFI_SUCCESS);
}
- NamePath = FileDevicePath (NULL, L"startup.nsh");
+ NamePath = FileDevicePath (NULL, mStartupScript);
//
// Try the first location
//
@@ -736,14 +754,20 @@ DoStartupScript( // If we got a file, run it
//
if (!EFI_ERROR(Status)) {
- Status = RunScriptFileHandle (FileHandle, L"startup.nsh");
+ Status = RunScriptFileHandle (FileHandle, mStartupScript);
ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);
} else {
- //
- // we return success since we dont need to have a startup script
- //
- Status = EFI_SUCCESS;
- ASSERT(FileHandle == NULL);
+ FileStringPath = ShellFindFilePath(mStartupScript);
+ if (FileStringPath == NULL) {
+ //
+ // we return success since we dont need to have a startup script
+ //
+ Status = EFI_SUCCESS;
+ ASSERT(FileHandle == NULL);
+ } else {
+ Status = RunScriptFile(FileStringPath);
+ FreePool(FileStringPath);
+ }
}
FreePool(NamePath);
@@ -993,6 +1017,12 @@ ShellConvertVariables ( NewCommandLine1 = AllocateZeroPool(NewSize);
NewCommandLine2 = AllocateZeroPool(NewSize);
ItemTemp = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16)));
+ if (NewCommandLine1 == NULL || NewCommandLine2 == NULL || ItemTemp == NULL) {
+ SHELL_FREE_NON_NULL(NewCommandLine1);
+ SHELL_FREE_NON_NULL(NewCommandLine2);
+ SHELL_FREE_NON_NULL(ItemTemp);
+ return (NULL);
+ }
StrCpy(NewCommandLine1, OriginalCommandLine);
for (MasterEnvList = EfiShellGetEnv(NULL)
; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL //&& *(MasterEnvList+1) != CHAR_NULL
@@ -1225,6 +1255,10 @@ RunCommand( PostAliasCmdLine = NULL;
}
+ if (PostVariableCmdLine == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
+
while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') {
PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL;
}
@@ -1481,13 +1515,19 @@ RunScriptFileHandle ( PreScriptEchoState = ShellCommandGetEchoState();
NewScriptFile = (SCRIPT_FILE*)AllocateZeroPool(sizeof(SCRIPT_FILE));
- ASSERT(NewScriptFile != NULL);
+ if (NewScriptFile == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
//
// Set up the name
//
ASSERT(NewScriptFile->ScriptName == NULL);
NewScriptFile->ScriptName = StrnCatGrow(&NewScriptFile->ScriptName, NULL, Name, 0);
+ if (NewScriptFile->ScriptName == NULL) {
+ DeleteScriptFileStruct(NewScriptFile);
+ return (EFI_OUT_OF_RESOURCES);
+ }
//
// Save the parameters (used to replace %0 to %9 later on)
@@ -1495,10 +1535,17 @@ RunScriptFileHandle ( NewScriptFile->Argc = ShellInfoObject.NewShellParametersProtocol->Argc;
if (NewScriptFile->Argc != 0) {
NewScriptFile->Argv = (CHAR16**)AllocateZeroPool(NewScriptFile->Argc * sizeof(CHAR16*));
- ASSERT(NewScriptFile->Argv != NULL);
+ if (NewScriptFile->Argv == NULL) {
+ DeleteScriptFileStruct(NewScriptFile);
+ return (EFI_OUT_OF_RESOURCES);
+ }
for (LoopVar = 0 ; LoopVar < 10 && LoopVar < NewScriptFile->Argc; LoopVar++) {
ASSERT(NewScriptFile->Argv[LoopVar] == NULL);
NewScriptFile->Argv[LoopVar] = StrnCatGrow(&NewScriptFile->Argv[LoopVar], NULL, ShellInfoObject.NewShellParametersProtocol->Argv[LoopVar], 0);
+ if (NewScriptFile->Argv[LoopVar] == NULL) {
+ DeleteScriptFileStruct(NewScriptFile);
+ return (EFI_OUT_OF_RESOURCES);
+ }
}
} else {
NewScriptFile->Argv = NULL;
@@ -1518,7 +1565,10 @@ RunScriptFileHandle ( continue;
}
NewScriptFile->CurrentCommand = AllocateZeroPool(sizeof(SCRIPT_COMMAND_LIST));
- ASSERT(NewScriptFile->CurrentCommand != NULL);
+ if (NewScriptFile->CurrentCommand == NULL) {
+ DeleteScriptFileStruct(NewScriptFile);
+ return (EFI_OUT_OF_RESOURCES);
+ }
NewScriptFile->CurrentCommand->Cl = CommandLine;
NewScriptFile->CurrentCommand->Data = NULL;
@@ -1536,12 +1586,22 @@ RunScriptFileHandle ( // Now enumerate through the commands and run each one.
//
CommandLine = AllocatePool(PcdGet16(PcdShellPrintBufferSize));
+ if (CommandLine == NULL) {
+ DeleteScriptFileStruct(NewScriptFile);
+ return (EFI_OUT_OF_RESOURCES);
+ }
CommandLine2 = AllocatePool(PcdGet16(PcdShellPrintBufferSize));
+ if (CommandLine2 == NULL) {
+ FreePool(CommandLine);
+ DeleteScriptFileStruct(NewScriptFile);
+ return (EFI_OUT_OF_RESOURCES);
+ }
for ( NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetFirstNode(&NewScriptFile->CommandList)
; !IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)
; // conditional increment in the body of the loop
){
+ ASSERT(CommandLine2 != NULL);
StrCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl);
//
@@ -1619,7 +1679,7 @@ RunScriptFileHandle ( for (CommandLine3 = CommandLine2 ; CommandLine3[0] == L' ' ; CommandLine3++);
- if (CommandLine3[0] == L':' ) {
+ if (CommandLine3 != NULL && CommandLine3[0] == L':' ) {
//
// This line is a goto target / label
//
diff --git a/ShellPkg/Application/Shell/ShellEnvVar.c b/ShellPkg/Application/Shell/ShellEnvVar.c index ff353c4e2a..cd55fa907b 100644 --- a/ShellPkg/Application/Shell/ShellEnvVar.c +++ b/ShellPkg/Application/Shell/ShellEnvVar.c @@ -144,27 +144,30 @@ GetEnvironmentVariableList( UINTN ValSize;
ENV_VAR_LIST *VarList;
- ASSERT(ListHead != NULL);
+ if (ListHead == NULL) {
+ return (EFI_INVALID_PARAMETER);
+ }
Status = gRT->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, &MaxStorSize, &RemStorSize, &MaxVarSize);
- ASSERT_EFI_ERROR(Status);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
NameSize = (UINTN)MaxVarSize;
VariableName = AllocatePool(NameSize);
+ if (VariableName == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
StrCpy(VariableName, L"");
- while (TRUE) {
+ while (!EFI_ERROR(Status)) {
NameSize = (UINTN)MaxVarSize;
Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);
if (Status == EFI_NOT_FOUND){
Status = EFI_SUCCESS;
break;
}
- ASSERT_EFI_ERROR(Status);
- if (EFI_ERROR(Status)) {
- break;
- }
- if (CompareGuid(&Guid, &gShellVariableGuid)){
+ if (!EFI_ERROR(Status) && CompareGuid(&Guid, &gShellVariableGuid)){
VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));
ValSize = 0;
Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);
@@ -173,12 +176,12 @@ GetEnvironmentVariableList( ASSERT(VarList->Val != NULL);
Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);
}
- ASSERT_EFI_ERROR(Status);
- VarList->Key = AllocatePool(StrSize(VariableName));
- ASSERT(VarList->Key != NULL);
- StrCpy(VarList->Key, VariableName);
-
- InsertTailList(ListHead, &VarList->Link);
+ if (!EFI_ERROR(Status)) {
+ VarList->Key = AllocatePool(StrSize(VariableName));
+ ASSERT(VarList->Key != NULL);
+ StrCpy(VarList->Key, VariableName);
+ InsertTailList(ListHead, &VarList->Link);
+ }
} // compare guid
} // while
FreePool(VariableName);
diff --git a/ShellPkg/Application/Shell/ShellManParser.c b/ShellPkg/Application/Shell/ShellManParser.c index fe9facb483..e184c78d4f 100644 --- a/ShellPkg/Application/Shell/ShellManParser.c +++ b/ShellPkg/Application/Shell/ShellManParser.c @@ -32,17 +32,23 @@ GetManFileName( )
{
CHAR16 *Buffer;
- ASSERT(ManFileName != NULL);
+ if (ManFileName == NULL) {
+ return (NULL);
+ }
//
// Fix the file name
//
if (StrnCmp(ManFileName+StrLen(ManFileName)-4, L".man", 4)==0) {
Buffer = AllocateZeroPool(StrSize(ManFileName));
- StrCpy(Buffer, ManFileName);
+ if (Buffer != NULL) {
+ StrCpy(Buffer, ManFileName);
+ }
} else {
Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));
- StrCpy(Buffer, ManFileName);
- StrCat(Buffer, L".man");
+ if (Buffer != NULL) {
+ StrCpy(Buffer, ManFileName);
+ StrCat(Buffer, L".man");
+ }
}
return (Buffer);
}
diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c index 914853fdbf..5e3e48b414 100644 --- a/ShellPkg/Application/Shell/ShellParametersProtocol.c +++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c @@ -280,7 +280,9 @@ CreatePopulateInstallShellParametersProtocol ( // Allocate the new structure
//
*NewShellParameters = AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL));
- ASSERT(NewShellParameters != NULL);
+ if ((*NewShellParameters) == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
//
// get loaded image protocol
@@ -307,19 +309,22 @@ CreatePopulateInstallShellParametersProtocol ( // no parameters via environment... ok
//
} else {
- ASSERT_EFI_ERROR(Status);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
}
if (Size == 0 && LoadedImage->LoadOptionsSize != 0) {
+ ASSERT(FullCommandLine == NULL);
//
// Now we need to include a NULL terminator in the size.
//
Size = LoadedImage->LoadOptionsSize + sizeof(FullCommandLine[0]);
FullCommandLine = AllocateZeroPool(Size);
}
- if (LoadedImage->LoadOptionsSize != 0){
- StrCpy(FullCommandLine, LoadedImage->LoadOptions);
- }
if (FullCommandLine != NULL) {
+ if (LoadedImage->LoadOptionsSize != 0){
+ StrCpy(FullCommandLine, LoadedImage->LoadOptions);
+ }
//
// Populate Argc and Argv
//
@@ -685,6 +690,8 @@ UpdateStdInStdOutStdErr( ||(StdInFileName != NULL && StdInVarName != NULL)
||(StdErrVarName != NULL && !IsVolatileEnv(StdErrVarName))
||(StdOutVarName != NULL && !IsVolatileEnv(StdOutVarName))
+ ||(StrStr(NewCommandLine, L"connect -r") != NULL
+ && (StdOutVarName != NULL || StdOutFileName != NULL || StdErrFileName != NULL || StdErrVarName != NULL))
){
Status = EFI_INVALID_PARAMETER;
} else {
@@ -733,31 +740,34 @@ UpdateStdInStdOutStdErr( ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdOutFileName);
}
Status = ShellOpenFileByName(StdOutFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
- ASSERT(TempHandle != NULL);
- if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
- //
- // Write out the UnicodeFileTag
- //
- Size = sizeof(CHAR16);
- TagBuffer[0] = UnicodeFileTag;
- TagBuffer[1] = CHAR_NULL;
- ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
- } else if (OutAppend) {
- //
- // Move to end of file
- //
- Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize(TempHandle, &FileSize);
+ if (TempHandle == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ } else {
+ if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
+ //
+ // Write out the UnicodeFileTag
+ //
+ Size = sizeof(CHAR16);
+ TagBuffer[0] = UnicodeFileTag;
+ TagBuffer[1] = CHAR_NULL;
+ ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
+ } else if (OutAppend) {
+ //
+ // Move to end of file
+ //
+ Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize(TempHandle, &FileSize);
+ if (!EFI_ERROR(Status)) {
+ Status = ShellInfoObject.NewEfiShellProtocol->SetFilePosition(TempHandle, FileSize);
+ }
+ }
+ if (!OutUnicode && !EFI_ERROR(Status)) {
+ TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
+ ASSERT(TempHandle != NULL);
+ }
if (!EFI_ERROR(Status)) {
- Status = ShellInfoObject.NewEfiShellProtocol->SetFilePosition(TempHandle, FileSize);
+ ShellParameters->StdOut = TempHandle;
}
}
- if (!OutUnicode && !EFI_ERROR(Status)) {
- TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
- ASSERT(TempHandle != NULL);
- }
- if (!EFI_ERROR(Status)) {
- ShellParameters->StdOut = TempHandle;
- }
}
//
diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c index 27488ab62e..eaec87971d 100644 --- a/ShellPkg/Application/Shell/ShellProtocol.c +++ b/ShellPkg/Application/Shell/ShellProtocol.c @@ -666,6 +666,9 @@ EfiShellGetDeviceName( }
if (Language == NULL) {
Lang = AllocatePool(AsciiStrSize(CompName2->SupportedLanguages));
+ if (Lang == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
AsciiStrCpy(Lang, CompName2->SupportedLanguages);
TempChar = AsciiStrStr(Lang, ";");
if (TempChar != NULL){
@@ -673,6 +676,9 @@ EfiShellGetDeviceName( }
} else {
Lang = AllocatePool(AsciiStrSize(Language));
+ if (Lang == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
AsciiStrCpy(Lang, Language);
}
Status = CompName2->GetControllerName(CompName2, DeviceHandle, NULL, Lang, &DeviceNameToReturn);
@@ -686,7 +692,7 @@ EfiShellGetDeviceName( FreePool(HandleList);
}
if (DeviceNameToReturn != NULL){
- ASSERT(BestDeviceName == NULL);
+ ASSERT(BestDeviceName != NULL);
StrnCatGrow(BestDeviceName, NULL, DeviceNameToReturn, 0);
return (EFI_SUCCESS);
}
@@ -2270,6 +2276,12 @@ EfiShellGetEnv( Size += 2*sizeof(CHAR16);
Buffer = AllocateZeroPool(Size);
+ if (Buffer == NULL) {
+ if (!IsListEmpty (&List)) {
+ FreeEnvironmentVariableList(&List);
+ }
+ return (NULL);
+ }
CurrentWriteLocation = (CHAR16*)Buffer;
for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List)
@@ -2284,7 +2296,9 @@ EfiShellGetEnv( //
// Free the list...
//
- FreeEnvironmentVariableList(&List);
+ if (!IsListEmpty (&List)) {
+ FreeEnvironmentVariableList(&List);
+ }
} else {
//
// We are doing a specific environment variable
@@ -2506,7 +2520,7 @@ EfiShellSetCurDir( TempString = NULL;
DirectoryName = NULL;
- if (FileSystem == NULL && Dir == NULL) {
+ if ((FileSystem == NULL && Dir == NULL) || Dir == NULL) {
return (EFI_INVALID_PARAMETER);
}
@@ -2733,6 +2747,10 @@ InternalEfiShellGetListAlias( RetSize = 0;
RetVal = NULL;
+ if (VariableName == NULL) {
+ return (NULL);
+ }
+
VariableName[0] = CHAR_NULL;
while (TRUE) {
|