public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] Fix edit on screens with more than 200 columns
@ 2017-01-24 13:13 Witt, Sebastian
  2017-01-24 16:27 ` Carsey, Jaben
  0 siblings, 1 reply; 6+ messages in thread
From: Witt, Sebastian @ 2017-01-24 13:13 UTC (permalink / raw)
  To: edk2-devel@lists.01.org

If the shell edit command is used on a screen with more than
200 columns, we get a buffer overflow. This increases the default buffer size to 400 columns and allocates a pool when this is not enough.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Sebastian Witt <sebastian.witt@siemens.com>

---
 .../UefiShellDebug1CommandsLib.c                          | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
index 6ebf002..d81dd01 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
@@ -302,12 +302,21 @@ EditorClearLine (
   IN UINTN LastRow
   )
 {
-  CHAR16 Line[200];
+  CHAR16 Buffer[400];
+  CHAR16 *Line = Buffer;
 
   if (Row == 0) {
     Row = 1;
   }
 
+  // If there are more columns than our buffer can contain, allocate new buffer
+  if (LastCol >= (sizeof (Buffer) / sizeof (CHAR16))) {
+    Line = AllocateZeroPool (LastCol*(sizeof(CHAR16) + 1));
+    if (Line == NULL) {
+      return;
+    }
+  }
+  
   //
   // prepare a blank line
   //
@@ -326,6 +335,10 @@ EditorClearLine (
   // print out the blank line
   //
   ShellPrintEx (0, ((INT32)Row) - 1, Line);
+  
+  // Free if allocated
+  if (Line != Buffer)
+    FreePool (Line);
 }
 
 /**
-- 
2.1.4

With best regards,
Sebastian Witt

Siemens AG
Digital Factory Division
Factory Automation
Automation Products and Systems
DF FA AS DH KHE 1
Oestliche Rheinbrueckenstr. 50
76187 Karlsruhe, Germany
Tel.: +49 721 595-5326
mailto:sebastian.witt@siemens.com

www.siemens.com/ingenuityforlife

Siemens Aktiengesellschaft: Chairman of the Supervisory Board: Gerhard Cromme; Managing Board: Joe Kaeser, Chairman, President and Chief Executive Officer; Roland Busch, Lisa Davis, Klaus Helmrich, Janina Kugel, Siegfried Russwurm, Ralf P. Thomas; Registered offices: Berlin and Munich, Germany; Commercial registries: Berlin Charlottenburg, HRB 12300, Munich, HRB 6684; WEEE-Reg.-No. DE 23691322


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

end of thread, other threads:[~2017-01-26 17:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-24 13:13 [PATCH] Fix edit on screens with more than 200 columns Witt, Sebastian
2017-01-24 16:27 ` Carsey, Jaben
2017-01-24 16:47   ` Witt, Sebastian
2017-01-24 17:36     ` Carsey, Jaben
2017-01-26  9:00       ` Witt, Sebastian
2017-01-26 17:05         ` Carsey, Jaben

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