public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gao, Zhichao" <zhichao.gao@intel.com>
To: "Zhang, Shenglei" <shenglei.zhang@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Ni, Ray" <ray.ni@intel.com>
Subject: Re: [PATCH] ShellPkg/Shell/FileHandleWrappers.c: Add check for MemFile->Buffer
Date: Mon, 14 Oct 2019 00:31:43 +0000	[thread overview]
Message-ID: <3CE959C139B4C44DBEA1810E3AA6F9000B85648C@SHSMSX101.ccr.corp.intel.com> (raw)
In-Reply-To: <20191012075115.10972-1-shenglei.zhang@intel.com>



> -----Original Message-----
> From: Zhang, Shenglei
> Sent: Saturday, October 12, 2019 3:51 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray <ray.ni@intel.com>; Gao, Zhichao <zhichao.gao@intel.com>
> Subject: [PATCH] ShellPkg/Shell/FileHandleWrappers.c: Add check for
> MemFile->Buffer
> 
> Add check for MemFile->Buffer.
> Return EFI_OUT_OF_RESOURCES if MemFile->Buffer is NULL.
> 
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Zhichao Gao <zhichao.gao@intel.com>
> Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
> ---
>  ShellPkg/Application/Shell/FileHandleWrappers.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c
> b/ShellPkg/Application/Shell/FileHandleWrappers.c
> index 587556c42495..673031c9c73a 100644
> --- a/ShellPkg/Application/Shell/FileHandleWrappers.c
> +++ b/ShellPkg/Application/Shell/FileHandleWrappers.c
> @@ -1644,7 +1644,10 @@ FileInterfaceMemWrite(
>      //
>      if ((UINTN)(MemFile->Position + (*BufferSize)) > (UINTN)(MemFile-
> >BufferSize)) {
>        MemFile->Buffer = ReallocatePool((UINTN)(MemFile->BufferSize),
> (UINTN)(MemFile->BufferSize) + (*BufferSize) +
> MEM_WRITE_REALLOC_OVERHEAD, MemFile->Buffer);
> -      MemFile->BufferSize += (*BufferSize) +
> MEM_WRITE_REALLOC_OVERHEAD;
> +      if (MemFile->Buffer == NULL){
> +        return EFI_OUT_OF_RESOURCES;
> +      }
> +      MemFile->BufferSize += (*BufferSize) +
> + MEM_WRITE_REALLOC_OVERHEAD;
>      }
>      CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, Buffer,
> *BufferSize);
>      MemFile->Position += (*BufferSize); @@ -1661,6 +1664,9 @@
> FileInterfaceMemWrite(
>      AsciiSPrint(AsciiBuffer, *BufferSize, "%S", Buffer);
>      if ((UINTN)(MemFile->Position + AsciiStrSize(AsciiBuffer)) >
> (UINTN)(MemFile->BufferSize)) {
>        MemFile->Buffer = ReallocatePool((UINTN)(MemFile->BufferSize),
> (UINTN)(MemFile->BufferSize) + AsciiStrSize(AsciiBuffer) +
> MEM_WRITE_REALLOC_OVERHEAD, MemFile->Buffer);
> +      if (MemFile->Buffer == NULL){
> +        return EFI_OUT_OF_RESOURCES;
> +      }

Before return the function, we should free all the allocated buffer, here missing the AsciiBuffer.

Thanks,
Zhichao

>        MemFile->BufferSize += AsciiStrSize(AsciiBuffer) +
> MEM_WRITE_REALLOC_OVERHEAD;
>      }
>      CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, AsciiBuffer,
> AsciiStrSize(AsciiBuffer));
> --
> 2.18.0.windows.1


      reply	other threads:[~2019-10-14  0:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-12  7:51 [PATCH] ShellPkg/Shell/FileHandleWrappers.c: Add check for MemFile->Buffer Zhang, Shenglei
2019-10-14  0:31 ` Gao, Zhichao [this message]

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=3CE959C139B4C44DBEA1810E3AA6F9000B85648C@SHSMSX101.ccr.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