summaryrefslogtreecommitdiff
path: root/ShellPkg/Application
diff options
context:
space:
mode:
authorJaben Carsey <Jaben.carsey@intel.com>2014-03-31 20:43:04 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2014-03-31 20:43:04 +0000
commit4b5168d852be0d641be73e8399622704998c183f (patch)
treeb6f067762995ecee5406be3408011a3f47f37b6e /ShellPkg/Application
parent3f4b148993b1099de49cf736356f628c3c1201da (diff)
downloadedk2-platforms-4b5168d852be0d641be73e8399622704998c183f.tar.xz
ShellPkg: Fix potential memory leak when failing to fully create a structure
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey <Jaben.carsey@intel.com> Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15423 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Application')
-rw-r--r--ShellPkg/Application/Shell/ShellProtocol.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c
index 65c3c46a46..c702a35914 100644
--- a/ShellPkg/Application/Shell/ShellProtocol.c
+++ b/ShellPkg/Application/Shell/ShellProtocol.c
@@ -1770,6 +1770,19 @@ EfiShellRemoveDupInFileList(
}
return (EFI_SUCCESS);
}
+
+//
+// This is the same structure as the external version, but it has no CONST qualifiers.
+//
+typedef struct {
+ LIST_ENTRY Link; ///< Linked list members.
+ EFI_STATUS Status; ///< Status of opening the file. Valid only if Handle != NULL.
+ CHAR16 *FullName; ///< Fully qualified filename.
+ CHAR16 *FileName; ///< name of this file.
+ SHELL_FILE_HANDLE Handle; ///< Handle for interacting with the opened file or NULL if closed.
+ EFI_FILE_INFO *Info; ///< Pointer to the FileInfo struct for this file or NULL.
+} EFI_SHELL_FILE_INFO_NO_CONST;
+
/**
Allocates and duplicates a EFI_SHELL_FILE_INFO node.
@@ -1786,7 +1799,12 @@ InternalDuplicateShellFileInfo(
IN BOOLEAN Save
)
{
- EFI_SHELL_FILE_INFO *NewNode;
+ EFI_SHELL_FILE_INFO_NO_CONST *NewNode;
+
+ //
+ // try to confirm that the objects are in sync
+ //
+ ASSERT(sizeof(EFI_SHELL_FILE_INFO_NO_CONST) == sizeof(EFI_SHELL_FILE_INFO));
NewNode = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
if (NewNode == NULL) {
@@ -1799,7 +1817,11 @@ InternalDuplicateShellFileInfo(
if ( NewNode->FullName == NULL
|| NewNode->FileName == NULL
|| NewNode->Info == NULL
- ){
+ ){
+ SHELL_FREE_NON_NULL(NewNode->FullName);
+ SHELL_FREE_NON_NULL(NewNode->FileName);
+ SHELL_FREE_NON_NULL(NewNode->Info);
+ SHELL_FREE_NON_NULL(NewNode);
return(NULL);
}
NewNode->Status = Node->Status;
@@ -1811,7 +1833,7 @@ InternalDuplicateShellFileInfo(
StrCpy((CHAR16*)NewNode->FileName, Node->FileName);
CopyMem(NewNode->Info, Node->Info, (UINTN)Node->Info->Size);
- return(NewNode);
+ return((EFI_SHELL_FILE_INFO*)NewNode);
}
/**