]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Add FileSize member to shell memory file structure.
authorJim_Dailey@Dell.com <Jim_Dailey@Dell.com>
Thu, 18 Feb 2016 14:40:46 +0000 (22:40 +0800)
committerLiming Gao <liming.gao@intel.com>
Thu, 3 Mar 2016 04:45:18 +0000 (12:45 +0800)
The shell uses the memory file structure to manage temporary files in
memory that support piping of output from one command into the the
input of another command.  The BufferSize member is the size of the
internal buffer, not the size of the data that was written to the
file. So, it was possible to read beyond the EOF of these files as
reads used BufferSize. Now FileSize tracks the actual size of these
files (the number of bytes written, not the number of bytes available
in the buffer), and the reads use this member.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jim Dailey <jim_dailey@dell.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ShellPkg/Application/Shell/FileHandleWrappers.c

index f8306e214704edf6fbd57adaa6db2f84d27ca88d..893e5ffc0466cc59f7b0dc38855848778ae14f3a 100644 (file)
@@ -1323,6 +1323,7 @@ typedef struct {
   UINT64                Position;\r
   UINT64                BufferSize;\r
   BOOLEAN               Unicode;\r
+  UINT64                FileSize;\r
 } EFI_FILE_PROTOCOL_MEM;\r
 \r
 /**\r
@@ -1341,7 +1342,7 @@ FileInterfaceMemSetPosition(
   OUT UINT64 Position\r
   )\r
 {\r
-  if (Position <= ((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize) {\r
+  if (Position <= ((EFI_FILE_PROTOCOL_MEM*)This)->FileSize) {\r
     ((EFI_FILE_PROTOCOL_MEM*)This)->Position = Position;\r
     return (EFI_SUCCESS);\r
   } else {\r
@@ -1400,6 +1401,7 @@ FileInterfaceMemWrite(
     }\r
     CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, Buffer, *BufferSize);\r
     MemFile->Position += (*BufferSize);\r
+    MemFile->FileSize = MemFile->Position;\r
     return (EFI_SUCCESS);\r
   } else {\r
     //\r
@@ -1416,6 +1418,7 @@ FileInterfaceMemWrite(
     }\r
     CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, AsciiBuffer, AsciiStrSize(AsciiBuffer));\r
     MemFile->Position += (*BufferSize / sizeof(CHAR16));\r
+    MemFile->FileSize = MemFile->Position;\r
     FreePool(AsciiBuffer);\r
     return (EFI_SUCCESS);\r
   }\r
@@ -1441,8 +1444,8 @@ FileInterfaceMemRead(
   EFI_FILE_PROTOCOL_MEM  *MemFile;\r
 \r
   MemFile = (EFI_FILE_PROTOCOL_MEM *) This;\r
-  if (*BufferSize > (UINTN)((MemFile->BufferSize) - (UINTN)(MemFile->Position))) {\r
-    (*BufferSize) = (UINTN)((MemFile->BufferSize) - (UINTN)(MemFile->Position));\r
+  if (*BufferSize > (UINTN)((MemFile->FileSize) - (UINTN)(MemFile->Position))) {\r
+    (*BufferSize) = (UINTN)((MemFile->FileSize) - (UINTN)(MemFile->Position));\r
   }\r
   CopyMem(Buffer, ((UINT8*)MemFile->Buffer) + MemFile->Position, (*BufferSize));\r
   MemFile->Position = MemFile->Position + (*BufferSize);\r