summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShenglei Zhang <shenglei.zhang@intel.com>2019-10-08 13:58:18 +0800
committerLiming Gao <liming.gao@intel.com>2019-11-06 13:26:21 +0800
commitdd6d07bda9e7ab3e4080d7be8bc140ded9a93eed (patch)
tree8a1df0844e4acc59ee245e6824d307388d58cb29
parent1bcc65b9a1408cf445b7b3f9499b27d9c235db71 (diff)
downloadedk2-dd6d07bda9e7ab3e4080d7be8bc140ded9a93eed.tar.gz
edk2-dd6d07bda9e7ab3e4080d7be8bc140ded9a93eed.tar.bz2
edk2-dd6d07bda9e7ab3e4080d7be8bc140ded9a93eed.zip
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> Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
-rw-r--r--ShellPkg/Application/Shell/FileHandleWrappers.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c
index 587556c424..2d7bd7bec6 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));