/** @file\r
File explorer related functions.\r
\r
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials are licensed and made available under\r
the terms and conditions of the BSD License that accompanies this distribution.\r
The full text of the license may be found at\r
return EFI_UNSUPPORTED;\r
}\r
\r
- *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
-\r
if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
if ((Value == NULL) || (ActionRequest == NULL)) {\r
return EFI_INVALID_PARAMETER;\r
FileContext = (FILE_CONTEXT *) MenuEntry->VariableContext;\r
\r
if (!FileContext->IsRoot) {\r
- FreePool (FileContext->DevicePath);\r
+ if (FileContext->DevicePath != NULL) {\r
+ FreePool (FileContext->DevicePath);\r
+ }\r
} else {\r
if (FileContext->FileHandle != NULL) {\r
FileContext->FileHandle->Close (FileContext->FileHandle);\r
\r
FreePool (FileContext);\r
\r
- FreePool (MenuEntry->DisplayString);\r
+ if (MenuEntry->DisplayString != NULL) {\r
+ FreePool (MenuEntry->DisplayString);\r
+ }\r
if (MenuEntry->HelpString != NULL) {\r
FreePool (MenuEntry->HelpString);\r
}\r
}\r
\r
TmpStr = AllocateCopyPool (StrSize (InputFileType), InputFileType);\r
+ ASSERT(TmpStr != NULL);\r
LibToLowerString(TmpStr);\r
\r
IsSupported = (StrStr (gFileExplorerPrivate.FileType, TmpStr) == NULL ? FALSE : TRUE);\r
\r
Size1 = StrSize (Str1);\r
Size2 = StrSize (Str2);\r
+ \r
+ //\r
+ // Check overflow\r
+ //\r
+ if (((MAX_UINTN - Size1) < Size2) || ((MAX_UINTN - Size1 - Size2) < sizeof(CHAR16))) {\r
+ return NULL;\r
+ }\r
+ \r
MaxLen = (Size1 + Size2 + sizeof (CHAR16))/ sizeof (CHAR16);\r
Str = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16));\r
ASSERT (Str != NULL);\r
MenuEntry->DisplayString,\r
NULL\r
);\r
- FreePool (Info);\r
+\r
+ if (Info != NULL)\r
+ FreePool (Info);\r
\r
OptionNumber++;\r
InsertTailList (&gFileExplorerPrivate.FsOptionMenu->Head, &MenuEntry->Link);\r
// the file system support below to be skipped.\r
//\r
Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
}\r
\r
//\r
*ParentFileName = AllocateCopyPool (StrSize (((FILEPATH_DEVICE_PATH *) DevicePathNode)->PathName), ((FILEPATH_DEVICE_PATH *) DevicePathNode)->PathName);\r
} else {\r
TempPath = LibAppendFileName (*ParentFileName, ((FILEPATH_DEVICE_PATH *) DevicePathNode)->PathName);\r
+ if (TempPath == NULL) {\r
+ LastHandle->Close (LastHandle);\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
FreePool (*ParentFileName);\r
*ParentFileName = TempPath;\r
}\r
// Pass 1 to get Directories\r
// Pass 2 to get files that are EFI images\r
//\r
+ Status = EFI_SUCCESS;\r
for (Pass = 1; Pass <= 2; Pass++) {\r
FileHandle->SetPosition (FileHandle, 0);\r
for (;;) {\r
BufferSize = DirBufferSize;\r
Status = FileHandle->Read (FileHandle, &BufferSize, DirInfo);\r
if (EFI_ERROR (Status) || BufferSize == 0) {\r
+ Status = EFI_SUCCESS;\r
break;\r
}\r
\r
\r
NewMenuEntry = LibCreateMenuEntry ();\r
if (NULL == NewMenuEntry) {\r
- return EFI_OUT_OF_RESOURCES;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
}\r
\r
NewFileContext = (FILE_CONTEXT *) NewMenuEntry->VariableContext;\r
NewFileContext->DeviceHandle = DeviceHandle;\r
NewFileContext->FileName = LibAppendFileName (FileName, DirInfo->FileName);\r
+ if (NewFileContext->FileName == NULL) {\r
+ LibDestroyMenuEntry (NewMenuEntry);\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
NewFileContext->FileHandle = FileHandle;\r
NewFileContext->DevicePath = FileDevicePath (NewFileContext->DeviceHandle, NewFileContext->FileName);\r
NewMenuEntry->HelpString = NULL;\r
\r
gFileExplorerPrivate.FsOptionMenu->MenuNumber = OptionNumber;\r
\r
+Done:\r
+\r
FreePool (DirInfo);\r
\r
- return EFI_SUCCESS;\r
+ return Status;\r
}\r
\r
/**\r
gFileExplorerPrivate.ChooseHandler = ChooseHandler;\r
if (FileType != NULL) {\r
gFileExplorerPrivate.FileType = AllocateCopyPool (StrSize (FileType), FileType);\r
+ ASSERT(gFileExplorerPrivate.FileType != NULL);\r
LibToLowerString(gFileExplorerPrivate.FileType);\r
} else {\r
gFileExplorerPrivate.FileType = NULL;\r
&gFileExplorerPrivate.FeConfigAccess,\r
NULL\r
);\r
- ASSERT_EFI_ERROR (Status);\r
+ if (Status == EFI_ALREADY_STARTED) {\r
+ return EFI_SUCCESS;\r
+ }\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
\r
//\r
// Post our File Explorer VFR binary to the HII database.\r
\r
ASSERT (gHiiVendorDevicePath != NULL);\r
\r
- Status = gBS->UninstallMultipleProtocolInterfaces (\r
- gFileExplorerPrivate.FeDriverHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- gHiiVendorDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- &gFileExplorerPrivate.FeConfigAccess,\r
- NULL\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
- \r
- HiiRemovePackages (gFileExplorerPrivate.FeHiiHandle);\r
+ if (gFileExplorerPrivate.FeDriverHandle != NULL) {\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ gFileExplorerPrivate.FeDriverHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ gHiiVendorDevicePath,\r
+ &gEfiHiiConfigAccessProtocolGuid,\r
+ &gFileExplorerPrivate.FeConfigAccess,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ \r
+ HiiRemovePackages (gFileExplorerPrivate.FeHiiHandle);\r
+ }\r
\r
FreePool (gHiiVendorDevicePath);\r
\r