[edk2-devel] [PATCH 31/35] ShellPkg/UefiShellDebug1CommandsLib: fix ShellCloseFile() call

Laszlo Ersek posted 35 patches 6 years, 4 months ago
[edk2-devel] [PATCH 31/35] ShellPkg/UefiShellDebug1CommandsLib: fix ShellCloseFile() call
Posted by Laszlo Ersek 6 years, 4 months ago
In the FileBufferSave() function, we invoke ShellCloseFile() if "Directory
Can Not Be Saved".

The ShellCloseFile() function takes a (SHELL_FILE_HANDLE*) parameter
called "FileHandle", and correctly passes the de-referenced (*FileHandle)
to EFI_SHELL_CLOSE_FILE, which takes a SHELL_FILE_HANDLE.

However, FileBufferSave() passes SHELL_FILE_HANDLE to ShellCloseFile(),
not the expected (SHELL_FILE_HANDLE*). Correct it.

This fixes an actual bug that has remained hidden for two reasons:

- pointer-to-VOID converts from/to any pointer-to-object type silently,
- the bug is on an error path which has likely never fired in practice.

Cc: Jaben Carsey <jaben.carsey@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---

Notes:
    tested: edit (saving a file)

 ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
index 464f9de38e52..fd324cc4a861 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
@@ -1462,7 +1462,7 @@ FileBufferSave (
 
     if (Info != NULL && Info->Attribute & EFI_FILE_DIRECTORY) {
       StatusBarSetStatusString (L"Directory Can Not Be Saved");
-      ShellCloseFile(FileHandle);
+      ShellCloseFile (&FileHandle);
       FreePool(Info);
       return EFI_LOAD_ERROR;
     }
-- 
2.19.1.3.g30247aa5d201



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47418): https://edk2.groups.io/g/devel/message/47418
Mute This Topic: https://groups.io/mt/34180234/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH 31/35] ShellPkg/UefiShellDebug1CommandsLib: fix ShellCloseFile() call
Posted by Philippe Mathieu-Daudé 6 years, 4 months ago
On 9/17/19 9:49 PM, Laszlo Ersek wrote:
> In the FileBufferSave() function, we invoke ShellCloseFile() if "Directory
> Can Not Be Saved".
> 
> The ShellCloseFile() function takes a (SHELL_FILE_HANDLE*) parameter
> called "FileHandle", and correctly passes the de-referenced (*FileHandle)
> to EFI_SHELL_CLOSE_FILE, which takes a SHELL_FILE_HANDLE.
> 
> However, FileBufferSave() passes SHELL_FILE_HANDLE to ShellCloseFile(),
> not the expected (SHELL_FILE_HANDLE*). Correct it.
> 
> This fixes an actual bug that has remained hidden for two reasons:
> 
> - pointer-to-VOID converts from/to any pointer-to-object type silently,
> - the bug is on an error path which has likely never fired in practice.
> 
> Cc: Jaben Carsey <jaben.carsey@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Zhichao Gao <zhichao.gao@intel.com>
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
> 
> Notes:
>     tested: edit (saving a file)
> 
>  ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> index 464f9de38e52..fd324cc4a861 100644
> --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> @@ -1462,7 +1462,7 @@ FileBufferSave (
>  
>      if (Info != NULL && Info->Attribute & EFI_FILE_DIRECTORY) {
>        StatusBarSetStatusString (L"Directory Can Not Be Saved");
> -      ShellCloseFile(FileHandle);
> +      ShellCloseFile (&FileHandle);
>        FreePool(Info);
>        return EFI_LOAD_ERROR;
>      }
> 

Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47847): https://edk2.groups.io/g/devel/message/47847
Mute This Topic: https://groups.io/mt/34180234/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH 31/35] ShellPkg/UefiShellDebug1CommandsLib: fix ShellCloseFile() call
Posted by Carsey, Jaben 6 years, 4 months ago
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

Thanks
-Jaben

> -----Original Message-----
> From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com]
> Sent: Monday, September 23, 2019 3:01 AM
> To: devel@edk2.groups.io; lersek@redhat.com
> Cc: Carsey, Jaben <jaben.carsey@intel.com>; Ni, Ray <ray.ni@intel.com>;
> Gao, Zhichao <zhichao.gao@intel.com>
> Subject: Re: [edk2-devel] [PATCH 31/35]
> ShellPkg/UefiShellDebug1CommandsLib: fix ShellCloseFile() call
> 
> On 9/17/19 9:49 PM, Laszlo Ersek wrote:
> > In the FileBufferSave() function, we invoke ShellCloseFile() if "Directory
> > Can Not Be Saved".
> >
> > The ShellCloseFile() function takes a (SHELL_FILE_HANDLE*) parameter
> > called "FileHandle", and correctly passes the de-referenced (*FileHandle)
> > to EFI_SHELL_CLOSE_FILE, which takes a SHELL_FILE_HANDLE.
> >
> > However, FileBufferSave() passes SHELL_FILE_HANDLE to ShellCloseFile(),
> > not the expected (SHELL_FILE_HANDLE*). Correct it.
> >
> > This fixes an actual bug that has remained hidden for two reasons:
> >
> > - pointer-to-VOID converts from/to any pointer-to-object type silently,
> > - the bug is on an error path which has likely never fired in practice.
> >
> > Cc: Jaben Carsey <jaben.carsey@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > Cc: Zhichao Gao <zhichao.gao@intel.com>
> > Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> > ---
> >
> > Notes:
> >     tested: edit (saving a file)
> >
> >  ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> > index 464f9de38e52..fd324cc4a861 100644
> > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> > +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> > @@ -1462,7 +1462,7 @@ FileBufferSave (
> >
> >      if (Info != NULL && Info->Attribute & EFI_FILE_DIRECTORY) {
> >        StatusBarSetStatusString (L"Directory Can Not Be Saved");
> > -      ShellCloseFile(FileHandle);
> > +      ShellCloseFile (&FileHandle);
> >        FreePool(Info);
> >        return EFI_LOAD_ERROR;
> >      }
> >
> 
> Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47853): https://edk2.groups.io/g/devel/message/47853
Mute This Topic: https://groups.io/mt/34180234/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH 31/35] ShellPkg/UefiShellDebug1CommandsLib: fix ShellCloseFile() call
Posted by Gao, Zhichao 6 years, 4 months ago
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>

> -----Original Message-----
> From: Carsey, Jaben
> Sent: Monday, September 23, 2019 10:29 PM
> To: Philippe Mathieu-Daudé <philmd@redhat.com>; devel@edk2.groups.io;
> lersek@redhat.com
> Cc: Ni, Ray <ray.ni@intel.com>; Gao, Zhichao <zhichao.gao@intel.com>
> Subject: RE: [edk2-devel] [PATCH 31/35]
> ShellPkg/UefiShellDebug1CommandsLib: fix ShellCloseFile() call
> 
> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
> 
> Thanks
> -Jaben
> 
> > -----Original Message-----
> > From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com]
> > Sent: Monday, September 23, 2019 3:01 AM
> > To: devel@edk2.groups.io; lersek@redhat.com
> > Cc: Carsey, Jaben <jaben.carsey@intel.com>; Ni, Ray
> > <ray.ni@intel.com>; Gao, Zhichao <zhichao.gao@intel.com>
> > Subject: Re: [edk2-devel] [PATCH 31/35]
> > ShellPkg/UefiShellDebug1CommandsLib: fix ShellCloseFile() call
> >
> > On 9/17/19 9:49 PM, Laszlo Ersek wrote:
> > > In the FileBufferSave() function, we invoke ShellCloseFile() if
> > > "Directory Can Not Be Saved".
> > >
> > > The ShellCloseFile() function takes a (SHELL_FILE_HANDLE*) parameter
> > > called "FileHandle", and correctly passes the de-referenced
> > > (*FileHandle) to EFI_SHELL_CLOSE_FILE, which takes a
> SHELL_FILE_HANDLE.
> > >
> > > However, FileBufferSave() passes SHELL_FILE_HANDLE to
> > > ShellCloseFile(), not the expected (SHELL_FILE_HANDLE*). Correct it.
> > >
> > > This fixes an actual bug that has remained hidden for two reasons:
> > >
> > > - pointer-to-VOID converts from/to any pointer-to-object type
> > > silently,
> > > - the bug is on an error path which has likely never fired in practice.
> > >
> > > Cc: Jaben Carsey <jaben.carsey@intel.com>
> > > Cc: Ray Ni <ray.ni@intel.com>
> > > Cc: Zhichao Gao <zhichao.gao@intel.com>
> > > Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> > > ---
> > >
> > > Notes:
> > >     tested: edit (saving a file)
> > >
> > >  ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c | 2
> > > +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git
> > a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> > b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> > > index 464f9de38e52..fd324cc4a861 100644
> > > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> > > +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> > > @@ -1462,7 +1462,7 @@ FileBufferSave (
> > >
> > >      if (Info != NULL && Info->Attribute & EFI_FILE_DIRECTORY) {
> > >        StatusBarSetStatusString (L"Directory Can Not Be Saved");
> > > -      ShellCloseFile(FileHandle);
> > > +      ShellCloseFile (&FileHandle);
> > >        FreePool(Info);
> > >        return EFI_LOAD_ERROR;
> > >      }
> > >
> >
> > Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47884): https://edk2.groups.io/g/devel/message/47884
Mute This Topic: https://groups.io/mt/34180234/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-