ShellPkg/Application/Shell/FileHandleWrappers.c | 7 +++++++ 1 file changed, 7 insertions(+)
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
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#48875): https://edk2.groups.io/g/devel/message/48875
Mute This Topic: https://groups.io/mt/34528724/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Refer to CSS 5.2.2.6 Always put space before an open parenthesis. FreePool(AsciiBuffer); should be FreePool (AsciiBuffer); After address that, Reviewed-by: Zhichao Gao <zhichao.gao@intel.com> Thanks, Zhichao > -----Original Message----- > From: Zhang, Shenglei > Sent: Monday, October 14, 2019 9:25 AM > To: devel@edk2.groups.io > Cc: Ni, Ray <ray.ni@intel.com>; Gao, Zhichao <zhichao.gao@intel.com> > Subject: [PATCH v2] 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> > --- > > 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 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#48879): https://edk2.groups.io/g/devel/message/48879 Mute This Topic: https://groups.io/mt/34528724/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
On 10/14/19 8:35 AM, Gao, Zhichao wrote: > Refer to CSS 5.2.2.6 Always put space before an open parenthesis. > FreePool(AsciiBuffer); should be FreePool (AsciiBuffer); > After address that, Reviewed-by: Zhichao Gao <zhichao.gao@intel.com> > > Thanks, > Zhichao > >> -----Original Message----- >> From: Zhang, Shenglei >> Sent: Monday, October 14, 2019 9:25 AM >> To: devel@edk2.groups.io >> Cc: Ni, Ray <ray.ni@intel.com>; Gao, Zhichao <zhichao.gao@intel.com> >> Subject: [PATCH v2] 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> >> --- >> >> 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){ Also "Always put space before an open brace (curly bracket)" >> + 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 > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#48885): https://edk2.groups.io/g/devel/message/48885 Mute This Topic: https://groups.io/mt/34528724/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
> -----Original Message----- > From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com] > Sent: Monday, October 14, 2019 5:39 PM > To: devel@edk2.groups.io; Gao, Zhichao <zhichao.gao@intel.com>; Zhang, > Shenglei <shenglei.zhang@intel.com> > Cc: Ni, Ray <ray.ni@intel.com> > Subject: Re: [edk2-devel] [PATCH v2] ShellPkg/Shell/FileHandleWrappers.c: > Add check for MemFile->Buffer > > On 10/14/19 8:35 AM, Gao, Zhichao wrote: > > Refer to CSS 5.2.2.6 Always put space before an open parenthesis. > > FreePool(AsciiBuffer); should be FreePool (AsciiBuffer); > > After address that, Reviewed-by: Zhichao Gao <zhichao.gao@intel.com> > > > > Thanks, > > Zhichao > > > >> -----Original Message----- > >> From: Zhang, Shenglei > >> Sent: Monday, October 14, 2019 9:25 AM > >> To: devel@edk2.groups.io > >> Cc: Ni, Ray <ray.ni@intel.com>; Gao, Zhichao <zhichao.gao@intel.com> > >> Subject: [PATCH v2] 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> > >> --- > >> > >> 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){ > > Also "Always put space before an open brace (curly bracket)" Sure. Thanks for pointing out this. I can do that before the patch is pushed. Thanks, Shenglei > > >> + 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 > > > > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#48905): https://edk2.groups.io/g/devel/message/48905 Mute This Topic: https://groups.io/mt/34528724/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2024 Red Hat, Inc.