Verify memory allocations were successful.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10909 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jcarsey 2010-10-04 16:30:40 +00:00
parent d38a107995
commit 9ea69f8a05
7 changed files with 165 additions and 111 deletions

View File

@ -103,8 +103,11 @@ typedef struct {
@param[in] Alias The alias to test for.
@param[in] CommandString The updated command string.
@param[in,out] List The list to search.
@retval EFI_SUCCESS The operation was completed successfully.
@retval EFI_OUT_OF_RESOURCES There was not enough free memory.
**/
VOID
EFI_STATUS
EFIAPI
InternalUpdateAliasOnList(
IN CONST CHAR16 *Alias,
@ -139,12 +142,16 @@ InternalUpdateAliasOnList(
}
if (!Found) {
Node = AllocateZeroPool(sizeof(ALIAS_LIST));
if (Node == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
ASSERT(Node->Alias == NULL);
Node->Alias = StrnCatGrow(&Node->Alias, NULL, Alias, 0);
ASSERT(Node->CommandString == NULL);
Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);
InsertTailList(List, &Node->Link);
}
return (EFI_SUCCESS);
}
/**

View File

@ -186,10 +186,19 @@ ShellCommandRunCd (
// change directory on other drive letter
//
Drive = AllocateZeroPool(StrSize(Param1));
if (Drive == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
ShellStatus = SHELL_OUT_OF_RESOURCES;
} else {
Drive = StrCpy(Drive, Param1);
Path = StrStr(Drive, L":");
*(++Path) = CHAR_NULL;
if (Path == Drive + StrLen(Drive)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
ShellStatus = SHELL_NOT_FOUND;
} else {
Status = gEfiShellProtocol->SetCurDir(Drive, ++Path);
}
if (Status == EFI_NOT_FOUND) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
@ -201,6 +210,7 @@ ShellCommandRunCd (
}
}
}
}
if (Drive != NULL) {
FreePool(Drive);

View File

@ -287,6 +287,13 @@ ValidateAndCopyFiles(
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
DestPath = AllocatePool(PathLen);
if (HiiOutput == NULL || HiiOutput == NULL || HiiResultOk == NULL) {
SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk);
return (SHELL_OUT_OF_RESOURCES);
}
//
// Go through the list of files to copy...
//

View File

@ -349,6 +349,10 @@ PrintLsOutput(
if (Rec){
DirectoryName = AllocatePool(LongestPath + 2*sizeof(CHAR16));
if (DirectoryName == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
ShellStatus = SHELL_OUT_OF_RESOURCES;
} else {
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
; !IsNull(&ListHead->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
@ -374,6 +378,7 @@ PrintLsOutput(
}
FreePool(DirectoryName);
}
}
FreePool(CorrectedPath);
ShellCloseFileMetaArg(&ListHead);

View File

@ -99,7 +99,7 @@ UpdateMapping (
//
// Find each handle with Simple File System
//
HandleList = GetHandleListByPotocol(&gEfiSimpleFileSystemProtocolGuid);
HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);
if (HandleList != NULL) {
//
// Do a count of the handles
@ -503,6 +503,9 @@ PerformMappingDisplay(
HandleBuffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
HandleBuffer = AllocatePool(BufferSize);
if (HandleBuffer == NULL) {
return (SHELL_OUT_OF_RESOURCES);
}
Status = gBS->LocateHandle(
ByProtocol,
&gEfiDevicePathProtocolGuid,
@ -542,6 +545,9 @@ PerformMappingDisplay(
if (Status == EFI_BUFFER_TOO_SMALL) {
FreePool(HandleBuffer);
HandleBuffer = AllocatePool(BufferSize);
if (HandleBuffer == NULL) {
return (SHELL_OUT_OF_RESOURCES);
}
Status = gBS->LocateHandle(
ByProtocol,
&gEfiBlockIoProtocolGuid,
@ -549,8 +555,7 @@ PerformMappingDisplay(
&BufferSize,
HandleBuffer);
}
ASSERT_EFI_ERROR(Status);
if (!EFI_ERROR(Status)) {
//
// Get the map name(s) for each one.
//
@ -580,6 +585,7 @@ PerformMappingDisplay(
HandleBuffer[LoopVar]);
}
FreePool(HandleBuffer);
}
return (SHELL_SUCCESS);
}

View File

@ -152,6 +152,10 @@ GetDestinationLocation(
NewSize = StrSize(Cwd);
NewSize += StrSize(DestDir);
DestPath = AllocateZeroPool(NewSize);
if (DestPath == NULL) {
ShellCloseFileMetaArg(&DestList);
return (SHELL_OUT_OF_RESOURCES);
}
StrCpy(DestPath, Cwd);
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
StrCat(DestPath, L"\\");
@ -162,6 +166,10 @@ GetDestinationLocation(
} else {
ASSERT(DestPath == NULL);
DestPath = StrnCatGrow(&DestPath, NULL, DestDir, 0);
if (DestPath == NULL) {
ShellCloseFileMetaArg(&DestList);
return (SHELL_OUT_OF_RESOURCES);
}
}
} else {
Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&DestList->Link);
@ -175,6 +183,10 @@ GetDestinationLocation(
}
if (ShellIsDirectory(Node->FullName)==EFI_SUCCESS) {
DestPath = AllocateZeroPool(StrSize(Node->FullName)+sizeof(CHAR16));
if (DestPath == NULL) {
ShellCloseFileMetaArg(&DestList);
return (SHELL_OUT_OF_RESOURCES);
}
StrCpy(DestPath, Node->FullName);
StrCat(DestPath, L"\\");
} else {
@ -287,7 +299,10 @@ ValidateAndMoveFiles(
NewSize = StrSize(DestPath);
NewSize += StrSize(Node->FileName) + sizeof(EFI_FILE_INFO) + sizeof(CHAR16);
NewFileInfo = AllocateZeroPool(NewSize);
ASSERT(NewFileInfo != NULL);
if (NewFileInfo == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
ShellStatus = SHELL_OUT_OF_RESOURCES;
} else {
CopyMem(NewFileInfo, Node->Info, sizeof(EFI_FILE_INFO));
if (DestPath[0] != L'\\') {
StrCpy(NewFileInfo->FileName, L"\\");
@ -344,6 +359,7 @@ ValidateAndMoveFiles(
} else {
ShellPrintEx(-1, -1, L"%s", HiiResultOk);
}
}
} // for loop
FreePool(DestPath);

View File

@ -41,6 +41,9 @@ PrintAllShellAlias(
return (SHELL_SUCCESS);
}
Alias = AllocateZeroPool(StrSize(ConstAllAliasList));
if (Alias == NULL) {
return (SHELL_OUT_OF_RESOURCES);
}
Walker = (CHAR16*)ConstAllAliasList;
do {