audk/ShellPkg/Library/UefiShellDebug1CommandsLib
Ruiyu Ni 004b811238 ShellPkg/edit: Fix heap access out-of-bounds
The issue was found when heap guard is turned on.
PrintLib somehow receives a non-null terminated string in var-arg.
When the PrintLib implementation reads the string it keeps
reading because no null-terminator is met, which triggers the page
fault set by the heap guard.

The issue is caused by a bug in FileBufferPrintLine().
When "edit" opens a binary file, in FileBufferPrintLine(),
the Line->Buffer may start with \x00 \x00, but the Line->Size is
larger than MainEditor.ScreenSize.Column, it causes the PrintLine is
set to an empty string by below call:
    StrnCpyS (
      PrintLine, BufLen/sizeof(CHAR16), Buffer,
      MIN(Limit, MainEditor.ScreenSize.Column)
      );
But since Limit (equals to Line->Size) is larger than
MainEditor.ScreenSize.Column, below for-loop doesn't successfully
set the whole PrintLine to all-empty-space.
    for (; Limit < MainEditor.ScreenSize.Column; Limit++) {
      PrintLine[Limit] = L' ';
    }
So after the for-loop, PrintLine is still an empty string.
Later in below call, the PrintLine2 is created based on PrintLine.
    ShellCopySearchAndReplace (
      PrintLine, PrintLine2,
      BufLen * 2, L"%", L"^%", FALSE, FALSE
      );
But due to the implementation of ShellCopySearchAndReplace(),
PrintLine2 is untouched and INVALID_PARAMETER is returned.
Finally an uninitialized string is passed to ShellPrintEx()
which causes the #PF exception.

The fix is to reset Limit to StrLen(PrintLine) before for-loop.
So that PrintLine can be converted from an empty string to a
string containing all spaces.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Jian Wang <jian.j.wang@intel.com>
2018-08-20 14:41:01 +08:00
..
Edit ShellPkg/edit: Fix heap access out-of-bounds 2018-08-20 14:41:01 +08:00
HexEdit ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
SmbiosView ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
Comp.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
Compress.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
Compress.h ShellPkg/UefiShellDebug1CommandsLib: sync Compress() definition with decl. 2018-02-08 18:21:11 +01:00
Dblk.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
Dmem.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
DmpStore.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
EditInputBar.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
EditInputBar.h ShellPkg/[hex]edit: use SimpleTextInEx to read console 2018-02-13 10:54:45 +08:00
EditMenuBar.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
EditMenuBar.h ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
EditStatusBar.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
EditStatusBar.h ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
EditTitleBar.c ShellPkg/UefiShellDebug1CommandsLib: Remove unnecessary EFIAPI 2016-10-09 10:27:47 +08:00
EditTitleBar.h ShellPkg/UefiShellDebug1CommandsLib: Remove unnecessary EFIAPI 2016-10-09 10:27:47 +08:00
EfiCompress.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
EfiDecompress.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
LoadPciRom.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
MemMap.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
Mm.c ShellPkg/UefiShellDebug1CommandsLib: remove I/O address limit from 'mm' 2018-03-01 17:01:30 +00:00
Mode.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
Pci.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
Pci.h ShellPkg/pci: Use PCI definitions defined in MdePkg 2017-01-25 16:09:05 +08:00
SerMode.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
SetSize.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
SetVar.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
UefiShellDebug1CommandsLib.c ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
UefiShellDebug1CommandsLib.h ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
UefiShellDebug1CommandsLib.inf ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00
UefiShellDebug1CommandsLib.uni ShellPkg: Clean up source files 2018-06-28 11:19:51 +08:00