public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Witt, Sebastian" <sebastian.witt@siemens.com>
To: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: [PATCH] Fix edit on screens with more than 200 columns
Date: Tue, 24 Jan 2017 13:13:59 +0000	[thread overview]
Message-ID: <5964EF557D87964BB107B86316EE26D21E0F4BB8@DEFTHW99EK3MSX.ww902.siemens.net> (raw)

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


             reply	other threads:[~2017-01-24 13:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-24 13:13 Witt, Sebastian [this message]
2017-01-24 16:27 ` [PATCH] Fix edit on screens with more than 200 columns 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5964EF557D87964BB107B86316EE26D21E0F4BB8@DEFTHW99EK3MSX.ww902.siemens.net \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox