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;
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;

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);
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;

View File

@ -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,8 +139,7 @@ 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);
if (!EFI_ERROR(Status)) {
//
// Enable the cursor to be visible
//
@ -308,6 +310,8 @@ UefiMain (
} 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 {
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
//

View File

@ -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);
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);

View File

@ -32,18 +32,24 @@ 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));
if (Buffer != NULL) {
StrCpy(Buffer, ManFileName);
}
} else {
Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));
if (Buffer != NULL) {
StrCpy(Buffer, ManFileName);
StrCat(Buffer, L".man");
}
}
return (Buffer);
}

View File

@ -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 (FullCommandLine != NULL) {
if (LoadedImage->LoadOptionsSize != 0){
StrCpy(FullCommandLine, LoadedImage->LoadOptions);
}
if (FullCommandLine != NULL) {
//
// 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,7 +740,9 @@ 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 (TempHandle == NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
//
// Write out the UnicodeFileTag
@ -759,6 +768,7 @@ UpdateStdInStdOutStdErr(
ShellParameters->StdOut = TempHandle;
}
}
}
//
// StdOut to a var

View File

@ -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...
//
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) {