diff options
author | Vladimir Olovyannikov via groups.io <vladimir.olovyannikov=broadcom.com@groups.io> | 2020-07-01 19:31:13 -0700 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2020-08-24 15:48:29 +0000 |
commit | 4535fc312b76cb5b05b6a8064c1c64d9780f55ba (patch) | |
tree | 1bf14b7c09e8a99605cab11f9aa28c86adb01625 | |
parent | d4e0b9607c9a64a8eff20724b2e35ea2cd5bd33f (diff) | |
download | edk2-4535fc312b76cb5b05b6a8064c1c64d9780f55ba.tar.gz edk2-4535fc312b76cb5b05b6a8064c1c64d9780f55ba.tar.bz2 edk2-4535fc312b76cb5b05b6a8064c1c64d9780f55ba.zip |
MdePkg: UefiFileHandleLib: fix buffer overrun in FileHandleReadLine()
If the size of the supplied buffer in FileHandleReadLine(), module
UefiFileHandleLib.c, was not 0, but was not enough to fit in
the line, the size is increased, and then the Buffer of the new
size is zeroed. This size is always larger than the supplied buffer size,
causing supplied buffer overrun. Fix the issue by using the
supplied buffer size in ZeroMem().
Signed-off-by: Vladimir Olovyannikov <vladimir.olovyannikov@broadcom.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Message-Id: <20200702023113.10517-1-vladimir.olovyannikov@broadcom.com>
Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>
[lersek@redhat.com: remove stray space character from subject line]
-rw-r--r-- | MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c index 28e28e5f67..ab34e6ccd5 100644 --- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c +++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c @@ -969,6 +969,7 @@ FileHandleReadLine( UINTN CharSize;
UINTN CountSoFar;
UINTN CrCount;
+ UINTN OldSize;
UINT64 OriginalFilePosition;
if (Handle == NULL
@@ -1039,10 +1040,11 @@ FileHandleReadLine( // if we ran out of space tell when...
//
if ((CountSoFar+1-CrCount)*sizeof(CHAR16) > *Size){
+ OldSize = *Size;
*Size = (CountSoFar+1-CrCount)*sizeof(CHAR16);
if (!Truncate) {
- if (Buffer != NULL && *Size != 0) {
- ZeroMem(Buffer, *Size);
+ if (Buffer != NULL && OldSize != 0) {
+ ZeroMem(Buffer, OldSize);
}
FileHandleSetPosition(Handle, OriginalFilePosition);
return (EFI_BUFFER_TOO_SMALL);
|