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