mirror of https://github.com/acidanthera/audk.git
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:
parent
d38a107995
commit
9ea69f8a05
|
@ -103,8 +103,11 @@ typedef struct {
|
||||||
@param[in] Alias The alias to test for.
|
@param[in] Alias The alias to test for.
|
||||||
@param[in] CommandString The updated command string.
|
@param[in] CommandString The updated command string.
|
||||||
@param[in,out] List The list to search.
|
@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
|
EFIAPI
|
||||||
InternalUpdateAliasOnList(
|
InternalUpdateAliasOnList(
|
||||||
IN CONST CHAR16 *Alias,
|
IN CONST CHAR16 *Alias,
|
||||||
|
@ -139,12 +142,16 @@ InternalUpdateAliasOnList(
|
||||||
}
|
}
|
||||||
if (!Found) {
|
if (!Found) {
|
||||||
Node = AllocateZeroPool(sizeof(ALIAS_LIST));
|
Node = AllocateZeroPool(sizeof(ALIAS_LIST));
|
||||||
|
if (Node == NULL) {
|
||||||
|
return (EFI_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
ASSERT(Node->Alias == NULL);
|
ASSERT(Node->Alias == NULL);
|
||||||
Node->Alias = StrnCatGrow(&Node->Alias, NULL, Alias, 0);
|
Node->Alias = StrnCatGrow(&Node->Alias, NULL, Alias, 0);
|
||||||
ASSERT(Node->CommandString == NULL);
|
ASSERT(Node->CommandString == NULL);
|
||||||
Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);
|
Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);
|
||||||
InsertTailList(List, &Node->Link);
|
InsertTailList(List, &Node->Link);
|
||||||
}
|
}
|
||||||
|
return (EFI_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -186,17 +186,27 @@ ShellCommandRunCd (
|
||||||
// change directory on other drive letter
|
// change directory on other drive letter
|
||||||
//
|
//
|
||||||
Drive = AllocateZeroPool(StrSize(Param1));
|
Drive = AllocateZeroPool(StrSize(Param1));
|
||||||
Drive = StrCpy(Drive, Param1);
|
if (Drive == NULL) {
|
||||||
Path = StrStr(Drive, L":");
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
|
||||||
*(++Path) = CHAR_NULL;
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||||
Status = gEfiShellProtocol->SetCurDir(Drive, ++Path);
|
} 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) {
|
if (Status == EFI_NOT_FOUND) {
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
|
||||||
Status = SHELL_NOT_FOUND;
|
Status = SHELL_NOT_FOUND;
|
||||||
} else if (EFI_ERROR(Status)) {
|
} else if (EFI_ERROR(Status)) {
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);
|
||||||
Status = SHELL_NOT_FOUND;
|
Status = SHELL_NOT_FOUND;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,6 +287,13 @@ ValidateAndCopyFiles(
|
||||||
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
|
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
|
||||||
DestPath = AllocatePool(PathLen);
|
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...
|
// Go through the list of files to copy...
|
||||||
//
|
//
|
||||||
|
|
|
@ -349,30 +349,35 @@ PrintLsOutput(
|
||||||
|
|
||||||
if (Rec){
|
if (Rec){
|
||||||
DirectoryName = AllocatePool(LongestPath + 2*sizeof(CHAR16));
|
DirectoryName = AllocatePool(LongestPath + 2*sizeof(CHAR16));
|
||||||
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
|
if (DirectoryName == NULL) {
|
||||||
; !IsNull(&ListHead->Link, &Node->Link)
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
|
||||||
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||||
){
|
} else {
|
||||||
//
|
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
|
||||||
// recurse on any directory except the traversing ones...
|
; !IsNull(&ListHead->Link, &Node->Link)
|
||||||
//
|
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
|
||||||
if (((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)
|
){
|
||||||
&& StrCmp(Node->FileName, L".") != 0
|
//
|
||||||
&& StrCmp(Node->FileName, L"..") != 0
|
// recurse on any directory except the traversing ones...
|
||||||
){
|
//
|
||||||
StrCpy(DirectoryName, Node->FullName);
|
if (((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)
|
||||||
StrCat(DirectoryName, L"\\*");
|
&& StrCmp(Node->FileName, L".") != 0
|
||||||
PrintLsOutput(
|
&& StrCmp(Node->FileName, L"..") != 0
|
||||||
Rec,
|
){
|
||||||
Attribs,
|
StrCpy(DirectoryName, Node->FullName);
|
||||||
Sfo,
|
StrCat(DirectoryName, L"\\*");
|
||||||
DirectoryName,
|
PrintLsOutput(
|
||||||
FALSE,
|
Rec,
|
||||||
Count,
|
Attribs,
|
||||||
TimeZone);
|
Sfo,
|
||||||
|
DirectoryName,
|
||||||
|
FALSE,
|
||||||
|
Count,
|
||||||
|
TimeZone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
FreePool(DirectoryName);
|
||||||
}
|
}
|
||||||
FreePool(DirectoryName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FreePool(CorrectedPath);
|
FreePool(CorrectedPath);
|
||||||
|
|
|
@ -99,7 +99,7 @@ UpdateMapping (
|
||||||
//
|
//
|
||||||
// Find each handle with Simple File System
|
// Find each handle with Simple File System
|
||||||
//
|
//
|
||||||
HandleList = GetHandleListByPotocol(&gEfiSimpleFileSystemProtocolGuid);
|
HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);
|
||||||
if (HandleList != NULL) {
|
if (HandleList != NULL) {
|
||||||
//
|
//
|
||||||
// Do a count of the handles
|
// Do a count of the handles
|
||||||
|
@ -503,6 +503,9 @@ PerformMappingDisplay(
|
||||||
HandleBuffer);
|
HandleBuffer);
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
HandleBuffer = AllocatePool(BufferSize);
|
HandleBuffer = AllocatePool(BufferSize);
|
||||||
|
if (HandleBuffer == NULL) {
|
||||||
|
return (SHELL_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
Status = gBS->LocateHandle(
|
Status = gBS->LocateHandle(
|
||||||
ByProtocol,
|
ByProtocol,
|
||||||
&gEfiDevicePathProtocolGuid,
|
&gEfiDevicePathProtocolGuid,
|
||||||
|
@ -542,6 +545,9 @@ PerformMappingDisplay(
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
FreePool(HandleBuffer);
|
FreePool(HandleBuffer);
|
||||||
HandleBuffer = AllocatePool(BufferSize);
|
HandleBuffer = AllocatePool(BufferSize);
|
||||||
|
if (HandleBuffer == NULL) {
|
||||||
|
return (SHELL_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
Status = gBS->LocateHandle(
|
Status = gBS->LocateHandle(
|
||||||
ByProtocol,
|
ByProtocol,
|
||||||
&gEfiBlockIoProtocolGuid,
|
&gEfiBlockIoProtocolGuid,
|
||||||
|
@ -549,37 +555,37 @@ PerformMappingDisplay(
|
||||||
&BufferSize,
|
&BufferSize,
|
||||||
HandleBuffer);
|
HandleBuffer);
|
||||||
}
|
}
|
||||||
ASSERT_EFI_ERROR(Status);
|
if (!EFI_ERROR(Status)) {
|
||||||
|
|
||||||
//
|
|
||||||
// Get the map name(s) for each one.
|
|
||||||
//
|
|
||||||
for ( LoopVar = 0
|
|
||||||
; LoopVar < BufferSize / sizeof(EFI_HANDLE)
|
|
||||||
; LoopVar ++
|
|
||||||
){
|
|
||||||
//
|
//
|
||||||
// Skip any that were already done...
|
// Get the map name(s) for each one.
|
||||||
//
|
//
|
||||||
if (gBS->OpenProtocol(
|
for ( LoopVar = 0
|
||||||
HandleBuffer[LoopVar],
|
; LoopVar < BufferSize / sizeof(EFI_HANDLE)
|
||||||
&gEfiDevicePathProtocolGuid,
|
; LoopVar ++
|
||||||
NULL,
|
){
|
||||||
gImageHandle,
|
//
|
||||||
NULL,
|
// Skip any that were already done...
|
||||||
EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {
|
//
|
||||||
continue;
|
if (gBS->OpenProtocol(
|
||||||
|
HandleBuffer[LoopVar],
|
||||||
|
&gEfiDevicePathProtocolGuid,
|
||||||
|
NULL,
|
||||||
|
gImageHandle,
|
||||||
|
NULL,
|
||||||
|
EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PerformSingleMappingDisplay(
|
||||||
|
Verbose,
|
||||||
|
Consist,
|
||||||
|
Normal,
|
||||||
|
Test,
|
||||||
|
SFO,
|
||||||
|
Specific,
|
||||||
|
HandleBuffer[LoopVar]);
|
||||||
}
|
}
|
||||||
PerformSingleMappingDisplay(
|
FreePool(HandleBuffer);
|
||||||
Verbose,
|
|
||||||
Consist,
|
|
||||||
Normal,
|
|
||||||
Test,
|
|
||||||
SFO,
|
|
||||||
Specific,
|
|
||||||
HandleBuffer[LoopVar]);
|
|
||||||
}
|
}
|
||||||
FreePool(HandleBuffer);
|
|
||||||
return (SHELL_SUCCESS);
|
return (SHELL_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,10 @@ GetDestinationLocation(
|
||||||
NewSize = StrSize(Cwd);
|
NewSize = StrSize(Cwd);
|
||||||
NewSize += StrSize(DestDir);
|
NewSize += StrSize(DestDir);
|
||||||
DestPath = AllocateZeroPool(NewSize);
|
DestPath = AllocateZeroPool(NewSize);
|
||||||
|
if (DestPath == NULL) {
|
||||||
|
ShellCloseFileMetaArg(&DestList);
|
||||||
|
return (SHELL_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
StrCpy(DestPath, Cwd);
|
StrCpy(DestPath, Cwd);
|
||||||
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
|
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
|
||||||
StrCat(DestPath, L"\\");
|
StrCat(DestPath, L"\\");
|
||||||
|
@ -162,6 +166,10 @@ GetDestinationLocation(
|
||||||
} else {
|
} else {
|
||||||
ASSERT(DestPath == NULL);
|
ASSERT(DestPath == NULL);
|
||||||
DestPath = StrnCatGrow(&DestPath, NULL, DestDir, 0);
|
DestPath = StrnCatGrow(&DestPath, NULL, DestDir, 0);
|
||||||
|
if (DestPath == NULL) {
|
||||||
|
ShellCloseFileMetaArg(&DestList);
|
||||||
|
return (SHELL_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&DestList->Link);
|
Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&DestList->Link);
|
||||||
|
@ -175,6 +183,10 @@ GetDestinationLocation(
|
||||||
}
|
}
|
||||||
if (ShellIsDirectory(Node->FullName)==EFI_SUCCESS) {
|
if (ShellIsDirectory(Node->FullName)==EFI_SUCCESS) {
|
||||||
DestPath = AllocateZeroPool(StrSize(Node->FullName)+sizeof(CHAR16));
|
DestPath = AllocateZeroPool(StrSize(Node->FullName)+sizeof(CHAR16));
|
||||||
|
if (DestPath == NULL) {
|
||||||
|
ShellCloseFileMetaArg(&DestList);
|
||||||
|
return (SHELL_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
StrCpy(DestPath, Node->FullName);
|
StrCpy(DestPath, Node->FullName);
|
||||||
StrCat(DestPath, L"\\");
|
StrCat(DestPath, L"\\");
|
||||||
} else {
|
} else {
|
||||||
|
@ -287,62 +299,66 @@ ValidateAndMoveFiles(
|
||||||
NewSize = StrSize(DestPath);
|
NewSize = StrSize(DestPath);
|
||||||
NewSize += StrSize(Node->FileName) + sizeof(EFI_FILE_INFO) + sizeof(CHAR16);
|
NewSize += StrSize(Node->FileName) + sizeof(EFI_FILE_INFO) + sizeof(CHAR16);
|
||||||
NewFileInfo = AllocateZeroPool(NewSize);
|
NewFileInfo = AllocateZeroPool(NewSize);
|
||||||
ASSERT(NewFileInfo != NULL);
|
if (NewFileInfo == NULL) {
|
||||||
CopyMem(NewFileInfo, Node->Info, sizeof(EFI_FILE_INFO));
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
|
||||||
if (DestPath[0] != L'\\') {
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||||
StrCpy(NewFileInfo->FileName, L"\\");
|
|
||||||
StrCat(NewFileInfo->FileName, DestPath);
|
|
||||||
} else {
|
} else {
|
||||||
StrCpy(NewFileInfo->FileName, DestPath);
|
CopyMem(NewFileInfo, Node->Info, sizeof(EFI_FILE_INFO));
|
||||||
}
|
if (DestPath[0] != L'\\') {
|
||||||
if (NewFileInfo->FileName[StrLen(NewFileInfo->FileName)-1] == L'\\') {
|
StrCpy(NewFileInfo->FileName, L"\\");
|
||||||
if (Node->FileName[0] == L'\\') {
|
StrCat(NewFileInfo->FileName, DestPath);
|
||||||
//
|
} else {
|
||||||
// Don't allow for double slashes. Eliminate one of them.
|
StrCpy(NewFileInfo->FileName, DestPath);
|
||||||
//
|
|
||||||
NewFileInfo->FileName[StrLen(NewFileInfo->FileName)-1] = CHAR_NULL;
|
|
||||||
}
|
}
|
||||||
StrCat(NewFileInfo->FileName, Node->FileName);
|
if (NewFileInfo->FileName[StrLen(NewFileInfo->FileName)-1] == L'\\') {
|
||||||
}
|
if (Node->FileName[0] == L'\\') {
|
||||||
NewFileInfo->Size = sizeof(EFI_FILE_INFO) + StrSize(NewFileInfo->FileName);
|
//
|
||||||
|
// Don't allow for double slashes. Eliminate one of them.
|
||||||
|
//
|
||||||
|
NewFileInfo->FileName[StrLen(NewFileInfo->FileName)-1] = CHAR_NULL;
|
||||||
|
}
|
||||||
|
StrCat(NewFileInfo->FileName, Node->FileName);
|
||||||
|
}
|
||||||
|
NewFileInfo->Size = sizeof(EFI_FILE_INFO) + StrSize(NewFileInfo->FileName);
|
||||||
|
|
||||||
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, NewFileInfo->FileName);
|
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, NewFileInfo->FileName);
|
||||||
|
|
||||||
//
|
|
||||||
// Perform the move operation
|
|
||||||
//
|
|
||||||
Status = ShellSetFileInfo(Node->Handle, NewFileInfo);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Free the info object we used...
|
|
||||||
//
|
|
||||||
ASSERT (NewFileInfo != NULL);
|
|
||||||
FreePool(NewFileInfo);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check our result
|
|
||||||
//
|
|
||||||
if (EFI_ERROR(Status)) {
|
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
|
|
||||||
//
|
//
|
||||||
// move failed
|
// Perform the move operation
|
||||||
//
|
//
|
||||||
switch(Status){
|
Status = ShellSetFileInfo(Node->Handle, NewFileInfo);
|
||||||
default:
|
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
//
|
||||||
case EFI_SECURITY_VIOLATION:
|
// Free the info object we used...
|
||||||
ShellStatus = SHELL_SECURITY_VIOLATION;
|
//
|
||||||
case EFI_WRITE_PROTECTED:
|
ASSERT (NewFileInfo != NULL);
|
||||||
ShellStatus = SHELL_WRITE_PROTECTED;
|
FreePool(NewFileInfo);
|
||||||
case EFI_OUT_OF_RESOURCES:
|
|
||||||
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
//
|
||||||
case EFI_DEVICE_ERROR:
|
// Check our result
|
||||||
ShellStatus = SHELL_DEVICE_ERROR;
|
//
|
||||||
case EFI_ACCESS_DENIED:
|
if (EFI_ERROR(Status)) {
|
||||||
ShellStatus = SHELL_ACCESS_DENIED;
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
|
||||||
} // switch
|
//
|
||||||
} else {
|
// move failed
|
||||||
ShellPrintEx(-1, -1, L"%s", HiiResultOk);
|
//
|
||||||
|
switch(Status){
|
||||||
|
default:
|
||||||
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
|
case EFI_SECURITY_VIOLATION:
|
||||||
|
ShellStatus = SHELL_SECURITY_VIOLATION;
|
||||||
|
case EFI_WRITE_PROTECTED:
|
||||||
|
ShellStatus = SHELL_WRITE_PROTECTED;
|
||||||
|
case EFI_OUT_OF_RESOURCES:
|
||||||
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||||
|
case EFI_DEVICE_ERROR:
|
||||||
|
ShellStatus = SHELL_DEVICE_ERROR;
|
||||||
|
case EFI_ACCESS_DENIED:
|
||||||
|
ShellStatus = SHELL_ACCESS_DENIED;
|
||||||
|
} // switch
|
||||||
|
} else {
|
||||||
|
ShellPrintEx(-1, -1, L"%s", HiiResultOk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // for loop
|
} // for loop
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,9 @@ PrintAllShellAlias(
|
||||||
return (SHELL_SUCCESS);
|
return (SHELL_SUCCESS);
|
||||||
}
|
}
|
||||||
Alias = AllocateZeroPool(StrSize(ConstAllAliasList));
|
Alias = AllocateZeroPool(StrSize(ConstAllAliasList));
|
||||||
|
if (Alias == NULL) {
|
||||||
|
return (SHELL_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
Walker = (CHAR16*)ConstAllAliasList;
|
Walker = (CHAR16*)ConstAllAliasList;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
Loading…
Reference in New Issue