mirror of https://github.com/acidanthera/audk.git
ShellPkg: Add FileSize member to shell memory file structure.
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>
This commit is contained in:
parent
b9da8fe0e3
commit
7bcd3ff611
|
@ -1323,6 +1323,7 @@ typedef struct {
|
||||||
UINT64 Position;
|
UINT64 Position;
|
||||||
UINT64 BufferSize;
|
UINT64 BufferSize;
|
||||||
BOOLEAN Unicode;
|
BOOLEAN Unicode;
|
||||||
|
UINT64 FileSize;
|
||||||
} EFI_FILE_PROTOCOL_MEM;
|
} EFI_FILE_PROTOCOL_MEM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1341,7 +1342,7 @@ FileInterfaceMemSetPosition(
|
||||||
OUT UINT64 Position
|
OUT UINT64 Position
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (Position <= ((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize) {
|
if (Position <= ((EFI_FILE_PROTOCOL_MEM*)This)->FileSize) {
|
||||||
((EFI_FILE_PROTOCOL_MEM*)This)->Position = Position;
|
((EFI_FILE_PROTOCOL_MEM*)This)->Position = Position;
|
||||||
return (EFI_SUCCESS);
|
return (EFI_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1400,6 +1401,7 @@ FileInterfaceMemWrite(
|
||||||
}
|
}
|
||||||
CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, Buffer, *BufferSize);
|
CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, Buffer, *BufferSize);
|
||||||
MemFile->Position += (*BufferSize);
|
MemFile->Position += (*BufferSize);
|
||||||
|
MemFile->FileSize = MemFile->Position;
|
||||||
return (EFI_SUCCESS);
|
return (EFI_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
|
@ -1416,6 +1418,7 @@ FileInterfaceMemWrite(
|
||||||
}
|
}
|
||||||
CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, AsciiBuffer, AsciiStrSize(AsciiBuffer));
|
CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, AsciiBuffer, AsciiStrSize(AsciiBuffer));
|
||||||
MemFile->Position += (*BufferSize / sizeof(CHAR16));
|
MemFile->Position += (*BufferSize / sizeof(CHAR16));
|
||||||
|
MemFile->FileSize = MemFile->Position;
|
||||||
FreePool(AsciiBuffer);
|
FreePool(AsciiBuffer);
|
||||||
return (EFI_SUCCESS);
|
return (EFI_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -1441,8 +1444,8 @@ FileInterfaceMemRead(
|
||||||
EFI_FILE_PROTOCOL_MEM *MemFile;
|
EFI_FILE_PROTOCOL_MEM *MemFile;
|
||||||
|
|
||||||
MemFile = (EFI_FILE_PROTOCOL_MEM *) This;
|
MemFile = (EFI_FILE_PROTOCOL_MEM *) This;
|
||||||
if (*BufferSize > (UINTN)((MemFile->BufferSize) - (UINTN)(MemFile->Position))) {
|
if (*BufferSize > (UINTN)((MemFile->FileSize) - (UINTN)(MemFile->Position))) {
|
||||||
(*BufferSize) = (UINTN)((MemFile->BufferSize) - (UINTN)(MemFile->Position));
|
(*BufferSize) = (UINTN)((MemFile->FileSize) - (UINTN)(MemFile->Position));
|
||||||
}
|
}
|
||||||
CopyMem(Buffer, ((UINT8*)MemFile->Buffer) + MemFile->Position, (*BufferSize));
|
CopyMem(Buffer, ((UINT8*)MemFile->Buffer) + MemFile->Position, (*BufferSize));
|
||||||
MemFile->Position = MemFile->Position + (*BufferSize);
|
MemFile->Position = MemFile->Position + (*BufferSize);
|
||||||
|
|
Loading…
Reference in New Issue