]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/editor: Fix system hang when console max column > 200
authorRuiyu Ni <ruiyu.ni@intel.com>
Thu, 19 Oct 2017 06:14:33 +0000 (14:14 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Mon, 23 Oct 2017 07:04:18 +0000 (15:04 +0800)
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>
ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c

index 8e2141bf4350c920a0318692a0f3203eccab03b2..d26d08f95c14c365ce2c6990eb55681172978950 100644 (file)
@@ -185,6 +185,7 @@ EditorClearLine (
   IN UINTN LastRow\r
   )\r
 {\r
   IN UINTN LastRow\r
   )\r
 {\r
+  UINTN  Col;\r
   CHAR16 Line[200];\r
 \r
   if (Row == 0) {\r
   CHAR16 Line[200];\r
 \r
   if (Row == 0) {\r
@@ -193,22 +194,28 @@ EditorClearLine (
 \r
   //\r
   // prepare a blank line\r
 \r
   //\r
   // prepare a blank line\r
+  // If max column is larger, split to multiple prints.\r
   //\r
   //\r
-  SetMem16(Line, LastCol*sizeof(CHAR16), L' ');\r
-\r
-  if (Row == LastRow) {\r
+  SetMem16 (Line, sizeof (Line), L' ');\r
+  Line[ARRAY_SIZE (Line) - 1] = CHAR_NULL;\r
+\r
+  for (Col = 1; Col <= LastCol; Col += ARRAY_SIZE (Line) - 1) {\r
+    if (Col + ARRAY_SIZE (Line) - 1 > LastCol) {\r
+      if (Row == LastRow) {\r
+        //\r
+        // if CHAR_NULL is still at position LastCol, it will cause first line error\r
+        //\r
+        Line[(LastCol % (ARRAY_SIZE (Line) - 1)) - 1] = CHAR_NULL;\r
+      } else {\r
+        Line[LastCol % (ARRAY_SIZE (Line) - 1)] = CHAR_NULL;\r
+      }\r
+    }\r
\r
     //\r
     //\r
-    // if CHAR_NULL is still at position 80, it will cause first line error\r
+    // print out the blank line\r
     //\r
     //\r
-    Line[LastCol - 1] = CHAR_NULL;\r
-  } else {\r
-    Line[LastCol] = CHAR_NULL;\r
+    ShellPrintEx ((INT32) Col - 1, (INT32) Row - 1, Line);\r
   }\r
   }\r
-\r
-  //\r
-  // print out the blank line\r
-  //\r
-  ShellPrintEx (0, ((INT32)Row) - 1, Line);\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r