public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] ShellPkg/Shell/FileHandleWrappers.c: Add check for MemFile->Buffer
@ 2019-10-14  1:25 Zhang, Shenglei
  2019-10-14  6:35 ` Gao, Zhichao
  0 siblings, 1 reply; 4+ messages in thread
From: Zhang, Shenglei @ 2019-10-14  1:25 UTC (permalink / raw)
  To: devel; +Cc: Ray Ni, Zhichao Gao

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>
---

v2: Add the expressiong to free AsciiBuffer before the function is returned.

 ShellPkg/Application/Shell/FileHandleWrappers.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c
index 587556c42495..2d7bd7bec67e 100644
--- a/ShellPkg/Application/Shell/FileHandleWrappers.c
+++ b/ShellPkg/Application/Shell/FileHandleWrappers.c
@@ -1644,6 +1644,9 @@ 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);
+      if (MemFile->Buffer == NULL){
+        return EFI_OUT_OF_RESOURCES;
+      }
       MemFile->BufferSize += (*BufferSize) + MEM_WRITE_REALLOC_OVERHEAD;
     }
     CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, Buffer, *BufferSize);
@@ -1661,6 +1664,10 @@ 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){
+        FreePool(AsciiBuffer);
+        return EFI_OUT_OF_RESOURCES;
+      }
       MemFile->BufferSize += AsciiStrSize(AsciiBuffer) + MEM_WRITE_REALLOC_OVERHEAD;
     }
     CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, AsciiBuffer, AsciiStrSize(AsciiBuffer));
-- 
2.18.0.windows.1


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

end of thread, other threads:[~2019-10-14 14:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-14  1:25 [PATCH v2] ShellPkg/Shell/FileHandleWrappers.c: Add check for MemFile->Buffer Zhang, Shenglei
2019-10-14  6:35 ` Gao, Zhichao
2019-10-14  9:38   ` [edk2-devel] " Philippe Mathieu-Daudé
2019-10-14 14:04     ` Zhang, Shenglei

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