diff options
author | Ruiyu Ni <ruiyu.ni@intel.com> | 2017-10-19 14:14:33 +0800 |
---|---|---|
committer | Ruiyu Ni <ruiyu.ni@intel.com> | 2017-10-23 15:04:18 +0800 |
commit | 1a421c2c173adece66f3c24f6d1cfb2ae5cee9cb (patch) | |
tree | 34b793baef2204e4e16e687cffc338a3de45960f | |
parent | b9e5df433641dfe7c597bfb7b15f2cce64e01e5b (diff) | |
download | edk2-1a421c2c173adece66f3c24f6d1cfb2ae5cee9cb.tar.gz edk2-1a421c2c173adece66f3c24f6d1cfb2ae5cee9cb.tar.bz2 edk2-1a421c2c173adece66f3c24f6d1cfb2ae5cee9cb.zip |
ShellPkg/editor: Fix system hang when console max column > 200
EditorClearLine() assumes the console max column is less than 200.
When the max column is bigger than 200, the code incorrectly
modifies the content out side of Line buffer.
It may cause system hang or reset.
The patch changes the function to print several times when
the max column is bigger than 200.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
-rw-r--r-- | ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c index 8e2141bf43..d26d08f95c 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c @@ -185,6 +185,7 @@ EditorClearLine ( IN UINTN LastRow
)
{
+ UINTN Col;
CHAR16 Line[200];
if (Row == 0) {
@@ -193,22 +194,28 @@ EditorClearLine ( //
// prepare a blank line
+ // If max column is larger, split to multiple prints.
//
- SetMem16(Line, LastCol*sizeof(CHAR16), L' ');
-
- if (Row == LastRow) {
+ SetMem16 (Line, sizeof (Line), L' ');
+ Line[ARRAY_SIZE (Line) - 1] = CHAR_NULL;
+
+ for (Col = 1; Col <= LastCol; Col += ARRAY_SIZE (Line) - 1) {
+ if (Col + ARRAY_SIZE (Line) - 1 > LastCol) {
+ if (Row == LastRow) {
+ //
+ // if CHAR_NULL is still at position LastCol, it will cause first line error
+ //
+ Line[(LastCol % (ARRAY_SIZE (Line) - 1)) - 1] = CHAR_NULL;
+ } else {
+ Line[LastCol % (ARRAY_SIZE (Line) - 1)] = CHAR_NULL;
+ }
+ }
+
//
- // if CHAR_NULL is still at position 80, it will cause first line error
+ // print out the blank line
//
- Line[LastCol - 1] = CHAR_NULL;
- } else {
- Line[LastCol] = CHAR_NULL;
+ ShellPrintEx ((INT32) Col - 1, (INT32) Row - 1, Line);
}
-
- //
- // print out the blank line
- //
- ShellPrintEx (0, ((INT32)Row) - 1, Line);
}
/**
|