public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Carsey, Jaben" <jaben.carsey@intel.com>
To: "Witt, Sebastian" <sebastian.witt@siemens.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Carsey, Jaben" <jaben.carsey@intel.com>
Subject: Re: [PATCH] Fix edit on screens with more than 200 columns
Date: Tue, 24 Jan 2017 17:36:15 +0000	[thread overview]
Message-ID: <CB6E33457884FA40993F35157061515C54B50E75@FMSMSX103.amr.corp.intel.com> (raw)
In-Reply-To: <5964EF557D87964BB107B86316EE26D21E0F4EA0@DEFTHW99EK3MSX.ww902.siemens.net>

I didn't mean a 400 static, I meant start by allocating 400 and simplify the end of the function...

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Witt, Sebastian
> Sent: Tuesday, January 24, 2017 8:48 AM
> To: Carsey, Jaben <jaben.carsey@intel.com>; edk2-devel@lists.01.org
> Subject: Re: [edk2] [PATCH] Fix edit on screens with more than 200 columns
> Importance: High
> 
> Only performance. But I haven't measured if there is a big difference
> between static buffer and AllocateZeroPool. I wouldn't use a fixed value.
> There may be a display device with more than 400 columns. Otherwise one
> can always allocate the [LastCol + 1] buffer.
> 
> -----Original Message-----
> From: Carsey, Jaben [mailto:jaben.carsey@intel.com]
> Sent: Dienstag, 24. Januar 2017 17:27
> To: Witt, Sebastian (DF FA AS DH KHE 1); edk2-devel@lists.01.org
> Cc: Carsey, Jaben
> Subject: RE: [PATCH] Fix edit on screens with more than 200 columns
> 
> Is there a reason to not just always start with allocating the 400 and then we
> don't need to complicate the end to conditionally free the buffer?
> 
> > -----Original Message-----
> > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> > Witt, Sebastian
> > Sent: Tuesday, January 24, 2017 5:14 AM
> > To: edk2-devel@lists.01.org
> > Subject: [edk2] [PATCH] Fix edit on screens with more than 200 columns
> > Importance: High
> >
> > 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/UefiShellDebug1Comman
> dsL
> > i
> > b.c
> >
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsL
> > i
> > b.c
> > index 6ebf002..d81dd01 100644
> > ---
> >
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsL
> > i
> > b.c
> > +++
> >
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> d
> > +++ sLib.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
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


  reply	other threads:[~2017-01-24 17:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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=CB6E33457884FA40993F35157061515C54B50E75@FMSMSX103.amr.corp.intel.com \
    --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