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
This commit is contained in:
jcarsey 2010-10-04 16:24:30 +00:00
parent aca84419c4
commit 3c865f2064
7 changed files with 328 additions and 226 deletions

View File

@ -39,8 +39,10 @@ ConsoleLoggerInstall(
EFI_STATUS Status; EFI_STATUS Status;
ASSERT(ConsoleInfo != NULL); ASSERT(ConsoleInfo != NULL);
*ConsoleInfo = AllocatePool(sizeof(CONSOLE_LOGGER_PRIVATE_DATA)); (*ConsoleInfo) = AllocatePool(sizeof(CONSOLE_LOGGER_PRIVATE_DATA));
ASSERT(ConsoleInfo != NULL); if ((*ConsoleInfo) == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
(*ConsoleInfo)->Signature = CONSOLE_LOGGER_PRIVATE_DATA_SIGNATURE; (*ConsoleInfo)->Signature = CONSOLE_LOGGER_PRIVATE_DATA_SIGNATURE;
(*ConsoleInfo)->OldConOut = NULL; (*ConsoleInfo)->OldConOut = NULL;

View File

@ -1406,7 +1406,7 @@ FileInterfaceMemClose(
) )
{ {
SHELL_FREE_NON_NULL(((EFI_FILE_PROTOCOL_MEM*)This)->Buffer); 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); return (EFI_SUCCESS);
} }
@ -1553,6 +1553,9 @@ CreateFileInterfaceFile(
EFI_FILE_PROTOCOL_FILE *NewOne; EFI_FILE_PROTOCOL_FILE *NewOne;
NewOne = AllocatePool(sizeof(EFI_FILE_PROTOCOL_FILE)); NewOne = AllocatePool(sizeof(EFI_FILE_PROTOCOL_FILE));
if (NewOne == NULL) {
return (NULL);
}
CopyMem(NewOne, Template, sizeof(EFI_FILE_PROTOCOL_FILE)); CopyMem(NewOne, Template, sizeof(EFI_FILE_PROTOCOL_FILE));
NewOne->Orig = (EFI_FILE_PROTOCOL *)Template; NewOne->Orig = (EFI_FILE_PROTOCOL *)Template;
NewOne->Unicode = Unicode; NewOne->Unicode = Unicode;

View File

@ -56,6 +56,7 @@ SHELL_INFO ShellInfoObject = {
STATIC CONST CHAR16 mScriptExtension[] = L".NSH"; STATIC CONST CHAR16 mScriptExtension[] = L".NSH";
STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI"; STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI";
STATIC CONST CHAR16 mStartupScript[] = L"startup.nsh";
/** /**
The entry point for the application. The entry point for the application.
@ -94,7 +95,9 @@ UefiMain (
// Clear the screen // Clear the screen
// //
Status = gST->ConOut->ClearScreen(gST->ConOut); Status = gST->ConOut->ClearScreen(gST->ConOut);
ASSERT_EFI_ERROR(Status); if (EFI_ERROR(Status)) {
return (Status);
}
// //
// Populate the global structure from PCDs // 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 // install our console logger. This will keep a log of the output for back-browsing
// //
Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo); Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo);
ASSERT_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
//
// 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
}
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);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// Check the command line
//
Status = ProcessCommandLine();
//
// If shell support level is >= 1 create the mappings and paths
//
if (PcdGet8(PcdShellSupportLevel) >= 1) {
Status = ShellCommandCreateInitialMappingsAndPaths();
}
//
// 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);
//
// 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
);
}
//
// Display the mapping
//
if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {
Status = RunCommand(L"map");
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);
}
Size = 100;
TempString = AllocateZeroPool(Size);
UnicodeSPrint(TempString, Size, L"%d", PcdGet8(PcdShellSupportLevel));
Status = InternalEfiShellSetEnv(L"uefishellsupport", TempString, TRUE);
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);
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);
FreePool(TempString);
if (!EFI_ERROR(Status)) { if (!EFI_ERROR(Status)) {
if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) { //
// // Enable the cursor to be visible
// Set up the event for CTRL-C monitoring... //
// gST->ConOut->EnableCursor (gST->ConOut, TRUE);
///@todo add support for using SimpleInputEx here //
// if SimpleInputEx is not available display a warning. // 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
}
if (ShellInfoObject.HiiHandle == NULL) {
return (EFI_NOT_STARTED);
}
} }
if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) { //
// // create and install the EfiShellParametersProtocol
// process the startup script or launch the called app. //
// Status = CreatePopulateInstallShellParametersProtocol(&ShellInfoObject.NewShellParametersProtocol, &ShellInfoObject.RootShellInstance);
Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath); 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);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// Check the command line
//
Status = ProcessCommandLine();
//
// If shell support level is >= 1 create the mappings and paths
//
if (PcdGet8(PcdShellSupportLevel) >= 1) {
Status = ShellCommandCreateInitialMappingsAndPaths();
} }
if ((PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) { //
// // save the device path for the loaded image and the device path for the filepath (under loaded image)
// begin the UI waiting loop // These are where to look for the startup.nsh file
// //
do { Status = GetDevicePathsForImageAndFile(&ShellInfoObject.ImageDevPath, &ShellInfoObject.FileDevPath);
// ASSERT_EFI_ERROR(Status);
// 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. // Display the version
// //
ShellInfoObject.PageBreakEnabled = PcdGetBool(PcdShellPageBreakDefault); if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion) {
ShellInfoObject.ConsoleInfo->Enabled = TRUE; ShellPrintHiiEx (
ShellInfoObject.ConsoleInfo->RowCounter = 0; 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
);
}
//
// Display the mapping
//
if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {
Status = RunCommand(L"map");
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);
}
Size = 100;
TempString = AllocateZeroPool(Size);
UnicodeSPrint(TempString, Size, L"%d", PcdGet8(PcdShellSupportLevel));
Status = InternalEfiShellSetEnv(L"uefishellsupport", TempString, TRUE);
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);
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);
FreePool(TempString);
if (!EFI_ERROR(Status)) {
if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {
// //
// Display Prompt // Set up the event for CTRL-C monitoring...
// //
Status = DoShellPrompt();
} while (!ShellCommandGetExit()); ///@todo add support for using SimpleInputEx here
// if SimpleInputEx is not available display a warning.
}
if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) {
//
// process the startup script or launch the called app.
//
Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);
}
if ((PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {
//
// begin the UI waiting loop
//
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... // uninstall protocols / free memory / etc...
// //
@ -342,7 +346,7 @@ UefiMain (
} }
if (!IsListEmpty(&ShellInfoObject.SplitList.Link)){ if (!IsListEmpty(&ShellInfoObject.SplitList.Link)){
ASSERT(FALSE); ASSERT(FALSE); ///@todo finish this de-allocation.
} }
if (ShellInfoObject.ShellInitSettings.FileName != NULL) { if (ShellInfoObject.ShellInitSettings.FileName != NULL) {
@ -579,6 +583,9 @@ ProcessCommandLine(
TempConst = ShellCommandLineGetRawValue(Package, Count++); TempConst = ShellCommandLineGetRawValue(Package, Count++);
if (TempConst != NULL && StrLen(TempConst)) { if (TempConst != NULL && StrLen(TempConst)) {
ShellInfoObject.ShellInitSettings.FileName = AllocatePool(StrSize(TempConst)); ShellInfoObject.ShellInitSettings.FileName = AllocatePool(StrSize(TempConst));
if (ShellInfoObject.ShellInitSettings.FileName == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
StrCpy(ShellInfoObject.ShellInitSettings.FileName, TempConst); StrCpy(ShellInfoObject.ShellInitSettings.FileName, TempConst);
ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = 1; ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = 1;
for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) { for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
@ -593,10 +600,18 @@ ProcessCommandLine(
&Size, &Size,
L" ", L" ",
0); 0);
if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {
SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);
return (EFI_OUT_OF_RESOURCES);
}
StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions, StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,
&Size, &Size,
gEfiShellParametersProtocol->Argv[LoopVar], gEfiShellParametersProtocol->Argv[LoopVar],
0); 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); NewSize += StrSize(ShellInfoObject.ShellInitSettings.FileOptions) + sizeof(CHAR16);
} }
FileStringPath = AllocateZeroPool(NewSize); FileStringPath = AllocateZeroPool(NewSize);
if (FileStringPath == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
StrCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName); StrCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName);
if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) { if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {
StrCat (FileStringPath, L" "); StrCat(FileStringPath, L" ");
StrCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions); StrCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions);
} }
Status = RunCommand(FileStringPath); Status = RunCommand(FileStringPath);
@ -717,7 +735,7 @@ DoStartupScript(
return (EFI_SUCCESS); return (EFI_SUCCESS);
} }
NamePath = FileDevicePath (NULL, L"startup.nsh"); NamePath = FileDevicePath (NULL, mStartupScript);
// //
// Try the first location // Try the first location
// //
@ -736,14 +754,20 @@ DoStartupScript(
// If we got a file, run it // If we got a file, run it
// //
if (!EFI_ERROR(Status)) { if (!EFI_ERROR(Status)) {
Status = RunScriptFileHandle (FileHandle, L"startup.nsh"); Status = RunScriptFileHandle (FileHandle, mStartupScript);
ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle); ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);
} else { } else {
// FileStringPath = ShellFindFilePath(mStartupScript);
// we return success since we dont need to have a startup script if (FileStringPath == NULL) {
// //
Status = EFI_SUCCESS; // we return success since we dont need to have a startup script
ASSERT(FileHandle == NULL); //
Status = EFI_SUCCESS;
ASSERT(FileHandle == NULL);
} else {
Status = RunScriptFile(FileStringPath);
FreePool(FileStringPath);
}
} }
FreePool(NamePath); FreePool(NamePath);
@ -993,6 +1017,12 @@ ShellConvertVariables (
NewCommandLine1 = AllocateZeroPool(NewSize); NewCommandLine1 = AllocateZeroPool(NewSize);
NewCommandLine2 = AllocateZeroPool(NewSize); NewCommandLine2 = AllocateZeroPool(NewSize);
ItemTemp = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16))); 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); StrCpy(NewCommandLine1, OriginalCommandLine);
for (MasterEnvList = EfiShellGetEnv(NULL) for (MasterEnvList = EfiShellGetEnv(NULL)
; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL //&& *(MasterEnvList+1) != CHAR_NULL ; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL //&& *(MasterEnvList+1) != CHAR_NULL
@ -1225,6 +1255,10 @@ RunCommand(
PostAliasCmdLine = NULL; PostAliasCmdLine = NULL;
} }
if (PostVariableCmdLine == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') { while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') {
PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL; PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL;
} }
@ -1481,13 +1515,19 @@ RunScriptFileHandle (
PreScriptEchoState = ShellCommandGetEchoState(); PreScriptEchoState = ShellCommandGetEchoState();
NewScriptFile = (SCRIPT_FILE*)AllocateZeroPool(sizeof(SCRIPT_FILE)); NewScriptFile = (SCRIPT_FILE*)AllocateZeroPool(sizeof(SCRIPT_FILE));
ASSERT(NewScriptFile != NULL); if (NewScriptFile == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
// //
// Set up the name // Set up the name
// //
ASSERT(NewScriptFile->ScriptName == NULL); ASSERT(NewScriptFile->ScriptName == NULL);
NewScriptFile->ScriptName = StrnCatGrow(&NewScriptFile->ScriptName, NULL, Name, 0); 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) // Save the parameters (used to replace %0 to %9 later on)
@ -1495,10 +1535,17 @@ RunScriptFileHandle (
NewScriptFile->Argc = ShellInfoObject.NewShellParametersProtocol->Argc; NewScriptFile->Argc = ShellInfoObject.NewShellParametersProtocol->Argc;
if (NewScriptFile->Argc != 0) { if (NewScriptFile->Argc != 0) {
NewScriptFile->Argv = (CHAR16**)AllocateZeroPool(NewScriptFile->Argc * sizeof(CHAR16*)); 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++) { for (LoopVar = 0 ; LoopVar < 10 && LoopVar < NewScriptFile->Argc; LoopVar++) {
ASSERT(NewScriptFile->Argv[LoopVar] == NULL); ASSERT(NewScriptFile->Argv[LoopVar] == NULL);
NewScriptFile->Argv[LoopVar] = StrnCatGrow(&NewScriptFile->Argv[LoopVar], NULL, ShellInfoObject.NewShellParametersProtocol->Argv[LoopVar], 0); 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 { } else {
NewScriptFile->Argv = NULL; NewScriptFile->Argv = NULL;
@ -1518,7 +1565,10 @@ RunScriptFileHandle (
continue; continue;
} }
NewScriptFile->CurrentCommand = AllocateZeroPool(sizeof(SCRIPT_COMMAND_LIST)); 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->Cl = CommandLine;
NewScriptFile->CurrentCommand->Data = NULL; NewScriptFile->CurrentCommand->Data = NULL;
@ -1536,12 +1586,22 @@ RunScriptFileHandle (
// Now enumerate through the commands and run each one. // Now enumerate through the commands and run each one.
// //
CommandLine = AllocatePool(PcdGet16(PcdShellPrintBufferSize)); CommandLine = AllocatePool(PcdGet16(PcdShellPrintBufferSize));
if (CommandLine == NULL) {
DeleteScriptFileStruct(NewScriptFile);
return (EFI_OUT_OF_RESOURCES);
}
CommandLine2 = AllocatePool(PcdGet16(PcdShellPrintBufferSize)); 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) for ( NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetFirstNode(&NewScriptFile->CommandList)
; !IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link) ; !IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)
; // conditional increment in the body of the loop ; // conditional increment in the body of the loop
){ ){
ASSERT(CommandLine2 != NULL);
StrCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl); StrCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl);
// //
@ -1619,7 +1679,7 @@ RunScriptFileHandle (
for (CommandLine3 = CommandLine2 ; CommandLine3[0] == L' ' ; CommandLine3++); for (CommandLine3 = CommandLine2 ; CommandLine3[0] == L' ' ; CommandLine3++);
if (CommandLine3[0] == L':' ) { if (CommandLine3 != NULL && CommandLine3[0] == L':' ) {
// //
// This line is a goto target / label // This line is a goto target / label
// //

View File

@ -144,27 +144,30 @@ GetEnvironmentVariableList(
UINTN ValSize; UINTN ValSize;
ENV_VAR_LIST *VarList; 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); 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; NameSize = (UINTN)MaxVarSize;
VariableName = AllocatePool(NameSize); VariableName = AllocatePool(NameSize);
if (VariableName == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
StrCpy(VariableName, L""); StrCpy(VariableName, L"");
while (TRUE) { while (!EFI_ERROR(Status)) {
NameSize = (UINTN)MaxVarSize; NameSize = (UINTN)MaxVarSize;
Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid); Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);
if (Status == EFI_NOT_FOUND){ if (Status == EFI_NOT_FOUND){
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
break; break;
} }
ASSERT_EFI_ERROR(Status); if (!EFI_ERROR(Status) && CompareGuid(&Guid, &gShellVariableGuid)){
if (EFI_ERROR(Status)) {
break;
}
if (CompareGuid(&Guid, &gShellVariableGuid)){
VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST)); VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));
ValSize = 0; ValSize = 0;
Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val); Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);
@ -173,12 +176,12 @@ GetEnvironmentVariableList(
ASSERT(VarList->Val != NULL); ASSERT(VarList->Val != NULL);
Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val); Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);
} }
ASSERT_EFI_ERROR(Status); if (!EFI_ERROR(Status)) {
VarList->Key = AllocatePool(StrSize(VariableName)); VarList->Key = AllocatePool(StrSize(VariableName));
ASSERT(VarList->Key != NULL); ASSERT(VarList->Key != NULL);
StrCpy(VarList->Key, VariableName); StrCpy(VarList->Key, VariableName);
InsertTailList(ListHead, &VarList->Link);
InsertTailList(ListHead, &VarList->Link); }
} // compare guid } // compare guid
} // while } // while
FreePool(VariableName); FreePool(VariableName);

View File

@ -32,17 +32,23 @@ GetManFileName(
) )
{ {
CHAR16 *Buffer; CHAR16 *Buffer;
ASSERT(ManFileName != NULL); if (ManFileName == NULL) {
return (NULL);
}
// //
// Fix the file name // Fix the file name
// //
if (StrnCmp(ManFileName+StrLen(ManFileName)-4, L".man", 4)==0) { if (StrnCmp(ManFileName+StrLen(ManFileName)-4, L".man", 4)==0) {
Buffer = AllocateZeroPool(StrSize(ManFileName)); Buffer = AllocateZeroPool(StrSize(ManFileName));
StrCpy(Buffer, ManFileName); if (Buffer != NULL) {
StrCpy(Buffer, ManFileName);
}
} else { } else {
Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16)); Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));
StrCpy(Buffer, ManFileName); if (Buffer != NULL) {
StrCat(Buffer, L".man"); StrCpy(Buffer, ManFileName);
StrCat(Buffer, L".man");
}
} }
return (Buffer); return (Buffer);
} }

View File

@ -280,7 +280,9 @@ CreatePopulateInstallShellParametersProtocol (
// Allocate the new structure // Allocate the new structure
// //
*NewShellParameters = AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL)); *NewShellParameters = AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL));
ASSERT(NewShellParameters != NULL); if ((*NewShellParameters) == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
// //
// get loaded image protocol // get loaded image protocol
@ -307,19 +309,22 @@ CreatePopulateInstallShellParametersProtocol (
// no parameters via environment... ok // no parameters via environment... ok
// //
} else { } else {
ASSERT_EFI_ERROR(Status); if (EFI_ERROR(Status)) {
return (Status);
}
} }
if (Size == 0 && LoadedImage->LoadOptionsSize != 0) { if (Size == 0 && LoadedImage->LoadOptionsSize != 0) {
ASSERT(FullCommandLine == NULL);
// //
// Now we need to include a NULL terminator in the size. // Now we need to include a NULL terminator in the size.
// //
Size = LoadedImage->LoadOptionsSize + sizeof(FullCommandLine[0]); Size = LoadedImage->LoadOptionsSize + sizeof(FullCommandLine[0]);
FullCommandLine = AllocateZeroPool(Size); FullCommandLine = AllocateZeroPool(Size);
} }
if (LoadedImage->LoadOptionsSize != 0){
StrCpy(FullCommandLine, LoadedImage->LoadOptions);
}
if (FullCommandLine != NULL) { if (FullCommandLine != NULL) {
if (LoadedImage->LoadOptionsSize != 0){
StrCpy(FullCommandLine, LoadedImage->LoadOptions);
}
// //
// Populate Argc and Argv // Populate Argc and Argv
// //
@ -685,6 +690,8 @@ UpdateStdInStdOutStdErr(
||(StdInFileName != NULL && StdInVarName != NULL) ||(StdInFileName != NULL && StdInVarName != NULL)
||(StdErrVarName != NULL && !IsVolatileEnv(StdErrVarName)) ||(StdErrVarName != NULL && !IsVolatileEnv(StdErrVarName))
||(StdOutVarName != NULL && !IsVolatileEnv(StdOutVarName)) ||(StdOutVarName != NULL && !IsVolatileEnv(StdOutVarName))
||(StrStr(NewCommandLine, L"connect -r") != NULL
&& (StdOutVarName != NULL || StdOutFileName != NULL || StdErrFileName != NULL || StdErrVarName != NULL))
){ ){
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
} else { } else {
@ -733,30 +740,33 @@ UpdateStdInStdOutStdErr(
ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdOutFileName); ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdOutFileName);
} }
Status = ShellOpenFileByName(StdOutFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0); Status = ShellOpenFileByName(StdOutFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
ASSERT(TempHandle != NULL); if (TempHandle == NULL) {
if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) { Status = EFI_INVALID_PARAMETER;
// } else {
// Write out the UnicodeFileTag if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
// //
Size = sizeof(CHAR16); // Write out the UnicodeFileTag
TagBuffer[0] = UnicodeFileTag; //
TagBuffer[1] = CHAR_NULL; Size = sizeof(CHAR16);
ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer); TagBuffer[0] = UnicodeFileTag;
} else if (OutAppend) { TagBuffer[1] = CHAR_NULL;
// ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
// Move to end of file } else if (OutAppend) {
// //
Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize(TempHandle, &FileSize); // Move to end of file
if (!EFI_ERROR(Status)) { //
Status = ShellInfoObject.NewEfiShellProtocol->SetFilePosition(TempHandle, FileSize); 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)) {
ShellParameters->StdOut = TempHandle;
} }
}
if (!OutUnicode && !EFI_ERROR(Status)) {
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
ASSERT(TempHandle != NULL);
}
if (!EFI_ERROR(Status)) {
ShellParameters->StdOut = TempHandle;
} }
} }

View File

@ -666,6 +666,9 @@ EfiShellGetDeviceName(
} }
if (Language == NULL) { if (Language == NULL) {
Lang = AllocatePool(AsciiStrSize(CompName2->SupportedLanguages)); Lang = AllocatePool(AsciiStrSize(CompName2->SupportedLanguages));
if (Lang == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Lang, CompName2->SupportedLanguages); AsciiStrCpy(Lang, CompName2->SupportedLanguages);
TempChar = AsciiStrStr(Lang, ";"); TempChar = AsciiStrStr(Lang, ";");
if (TempChar != NULL){ if (TempChar != NULL){
@ -673,6 +676,9 @@ EfiShellGetDeviceName(
} }
} else { } else {
Lang = AllocatePool(AsciiStrSize(Language)); Lang = AllocatePool(AsciiStrSize(Language));
if (Lang == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Lang, Language); AsciiStrCpy(Lang, Language);
} }
Status = CompName2->GetControllerName(CompName2, DeviceHandle, NULL, Lang, &DeviceNameToReturn); Status = CompName2->GetControllerName(CompName2, DeviceHandle, NULL, Lang, &DeviceNameToReturn);
@ -686,7 +692,7 @@ EfiShellGetDeviceName(
FreePool(HandleList); FreePool(HandleList);
} }
if (DeviceNameToReturn != NULL){ if (DeviceNameToReturn != NULL){
ASSERT(BestDeviceName == NULL); ASSERT(BestDeviceName != NULL);
StrnCatGrow(BestDeviceName, NULL, DeviceNameToReturn, 0); StrnCatGrow(BestDeviceName, NULL, DeviceNameToReturn, 0);
return (EFI_SUCCESS); return (EFI_SUCCESS);
} }
@ -2270,6 +2276,12 @@ EfiShellGetEnv(
Size += 2*sizeof(CHAR16); Size += 2*sizeof(CHAR16);
Buffer = AllocateZeroPool(Size); Buffer = AllocateZeroPool(Size);
if (Buffer == NULL) {
if (!IsListEmpty (&List)) {
FreeEnvironmentVariableList(&List);
}
return (NULL);
}
CurrentWriteLocation = (CHAR16*)Buffer; CurrentWriteLocation = (CHAR16*)Buffer;
for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List) for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List)
@ -2284,7 +2296,9 @@ EfiShellGetEnv(
// //
// Free the list... // Free the list...
// //
FreeEnvironmentVariableList(&List); if (!IsListEmpty (&List)) {
FreeEnvironmentVariableList(&List);
}
} else { } else {
// //
// We are doing a specific environment variable // We are doing a specific environment variable
@ -2506,7 +2520,7 @@ EfiShellSetCurDir(
TempString = NULL; TempString = NULL;
DirectoryName = NULL; DirectoryName = NULL;
if (FileSystem == NULL && Dir == NULL) { if ((FileSystem == NULL && Dir == NULL) || Dir == NULL) {
return (EFI_INVALID_PARAMETER); return (EFI_INVALID_PARAMETER);
} }
@ -2733,6 +2747,10 @@ InternalEfiShellGetListAlias(
RetSize = 0; RetSize = 0;
RetVal = NULL; RetVal = NULL;
if (VariableName == NULL) {
return (NULL);
}
VariableName[0] = CHAR_NULL; VariableName[0] = CHAR_NULL;
while (TRUE) { while (TRUE) {