public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] ShellPkg/editor: Fix system hang when console max column > 200
@ 2017-10-19  6:14 Ruiyu Ni
  2017-10-19 14:45 ` Carsey, Jaben
  0 siblings, 1 reply; 2+ messages in thread
From: Ruiyu Ni @ 2017-10-19  6:14 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jaben Carsey

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>
Cc: Jaben Carsey <jaben.carsey@intel.com>
---
 .../UefiShellDebug1CommandsLib.c                   | 31 +++++++++++++---------
 1 file 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);
 }
 
 /**
-- 
2.12.2.windows.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ShellPkg/editor: Fix system hang when console max column > 200
  2017-10-19  6:14 [PATCH] ShellPkg/editor: Fix system hang when console max column > 200 Ruiyu Ni
@ 2017-10-19 14:45 ` Carsey, Jaben
  0 siblings, 0 replies; 2+ messages in thread
From: Carsey, Jaben @ 2017-10-19 14:45 UTC (permalink / raw)
  To: Ni, Ruiyu, edk2-devel@lists.01.org

Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

> -----Original Message-----
> From: Ni, Ruiyu
> Sent: Wednesday, October 18, 2017 11:15 PM
> To: edk2-devel@lists.01.org
> Cc: Carsey, Jaben <jaben.carsey@intel.com>
> Subject: [PATCH] ShellPkg/editor: Fix system hang when console max column
> > 200
> Importance: High
> 
> 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>
> Cc: Jaben Carsey <jaben.carsey@intel.com>
> ---
>  .../UefiShellDebug1CommandsLib.c                   | 31 +++++++++++++---------
>  1 file changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.c
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.c
> index 8e2141bf43..d26d08f95c 100644
> ---
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.c
> +++
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.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);
>  }
> 
>  /**
> --
> 2.12.2.windows.2



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-19 14:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-19  6:14 [PATCH] ShellPkg/editor: Fix system hang when console max column > 200 Ruiyu Ni
2017-10-19 14:45 ` Carsey, Jaben

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox