public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak
@ 2019-05-10  3:24 Heinrich Schuchardt
  2019-05-10 14:32 ` [edk2-devel] " Carsey, Jaben
  0 siblings, 1 reply; 5+ messages in thread
From: Heinrich Schuchardt @ 2019-05-10  3:24 UTC (permalink / raw)
  To: Zhichao Gao
  Cc: devel @ edk2 . groups . io, Jaben Carsey, Ray Ni, Leif Lindholm,
	Liming Gao, Heinrich Schuchardt

Since TianoCore EDK2 commit d65f2cea36d1 ("ShellPkg/CommandLib: Locate
proper UnicodeCollation instance") in edk2 the UEFI Shell crashes if EFI
variable PlatformLang is not defined due to dereferencing gUnicodeCollation
gUnicodeCollation (= NULL) in ShellCommandRegisterCommandName().

Furthermore CommandInit() is leaking PlatformLang if
gUnicodeCollation != NULL.

Close the memory leak and use the first UnicodeCollation instance if
PlatfomLang is not defined.

Fixes: d65f2cea36d1 ("ShellPkg/CommandLib: Locate proper UnicodeCollation
instance")
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
---
v3
	resend as quoted-printable
---
 .../UefiShellCommandLib/UefiShellCommandLib.c | 20 +++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
index ddc4bb1567..e60279e5ac 100644
--- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
+++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
@@ -80,12 +80,10 @@ CommandInit(
   EFI_STATUS                      Status;
   CHAR8                           *PlatformLang;
 
-  GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL);
-  if (PlatformLang == NULL) {
-    return EFI_UNSUPPORTED;
-  }
-
   if (gUnicodeCollation == NULL) {
+
+    GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL);
+
     Status = gBS->LocateHandleBuffer (
                     ByProtocol,
                     &gEfiUnicodeCollation2ProtocolGuid,
@@ -113,6 +111,14 @@ CommandInit(
         continue;
       }
 
+      //
+      // Without clue provided use the first Unicode Collation2 protocol.
+      //
+      if (PlatformLang == NULL) {
+        gUnicodeCollation = Uc;
+        break;
+      }
+
       //
       // Find the best matching matching language from the supported languages
       // of Unicode Collation2 protocol.
@@ -132,7 +138,9 @@ CommandInit(
     if (Handles != NULL) {
       FreePool (Handles);
     }
-    FreePool (PlatformLang);
+    if (PlatformLang != NULL) {
+      FreePool (PlatformLang);
+    }
   }
 
   return (gUnicodeCollation == NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS;
-- 
2.20.1


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

* Re: [edk2-devel] [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak
  2019-05-10  3:24 [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak Heinrich Schuchardt
@ 2019-05-10 14:32 ` Carsey, Jaben
  2019-09-02 10:14   ` Heinrich Schuchardt
  0 siblings, 1 reply; 5+ messages in thread
From: Carsey, Jaben @ 2019-05-10 14:32 UTC (permalink / raw)
  To: devel@edk2.groups.io, xypron.glpk@gmx.de, Gao, Zhichao
  Cc: Ni, Ray, Leif Lindholm, Gao, Liming

Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

Code change looks good visually.


> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Heinrich Schuchardt
> Sent: Thursday, May 09, 2019 8:24 PM
> To: Gao, Zhichao <zhichao.gao@intel.com>
> Cc: devel @ edk2 . groups . io <devel@edk2.groups.io>; Carsey, Jaben
> <jaben.carsey@intel.com>; Ni, Ray <ray.ni@intel.com>; Leif Lindholm
> <leif.lindholm@linaro.org>; Gao, Liming <liming.gao@intel.com>; Heinrich
> Schuchardt <xypron.glpk@gmx.de>
> Subject: [edk2-devel] [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL
> derefence and memory leak
> Importance: High
> 
> Since TianoCore EDK2 commit d65f2cea36d1 ("ShellPkg/CommandLib: Locate
> proper UnicodeCollation instance") in edk2 the UEFI Shell crashes if EFI
> variable PlatformLang is not defined due to dereferencing gUnicodeCollation
> gUnicodeCollation (= NULL) in ShellCommandRegisterCommandName().
> 
> Furthermore CommandInit() is leaking PlatformLang if
> gUnicodeCollation != NULL.
> 
> Close the memory leak and use the first UnicodeCollation instance if
> PlatfomLang is not defined.
> 
> Fixes: d65f2cea36d1 ("ShellPkg/CommandLib: Locate proper
> UnicodeCollation
> instance")
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
> ---
> v3
> 	resend as quoted-printable
> ---
>  .../UefiShellCommandLib/UefiShellCommandLib.c | 20 +++++++++++++-----
> -
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
> b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
> index ddc4bb1567..e60279e5ac 100644
> --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
> +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
> @@ -80,12 +80,10 @@ CommandInit(
>    EFI_STATUS                      Status;
> 
>    CHAR8                           *PlatformLang;
> 
> 
> 
> -  GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME,
> (VOID**)&PlatformLang, NULL);
> 
> -  if (PlatformLang == NULL) {
> 
> -    return EFI_UNSUPPORTED;
> 
> -  }
> 
> -
> 
>    if (gUnicodeCollation == NULL) {
> 
> +
> 
> +    GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME,
> (VOID**)&PlatformLang, NULL);
> 
> +
> 
>      Status = gBS->LocateHandleBuffer (
> 
>                      ByProtocol,
> 
>                      &gEfiUnicodeCollation2ProtocolGuid,
> 
> @@ -113,6 +111,14 @@ CommandInit(
>          continue;
> 
>        }
> 
> 
> 
> +      //
> 
> +      // Without clue provided use the first Unicode Collation2 protocol.
> 
> +      //
> 
> +      if (PlatformLang == NULL) {
> 
> +        gUnicodeCollation = Uc;
> 
> +        break;
> 
> +      }
> 
> +
> 
>        //
> 
>        // Find the best matching matching language from the supported
> languages
> 
>        // of Unicode Collation2 protocol.
> 
> @@ -132,7 +138,9 @@ CommandInit(
>      if (Handles != NULL) {
> 
>        FreePool (Handles);
> 
>      }
> 
> -    FreePool (PlatformLang);
> 
> +    if (PlatformLang != NULL) {
> 
> +      FreePool (PlatformLang);
> 
> +    }
> 
>    }
> 
> 
> 
>    return (gUnicodeCollation == NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS;
> 
> --
> 2.20.1
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> 
> View/Reply Online (#40395): https://edk2.groups.io/g/devel/message/40395
> Mute This Topic: https://groups.io/mt/31573312/1760878
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub
> [jaben.carsey@intel.com]
> -=-=-=-=-=-=


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

* Re: [edk2-devel] [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak
  2019-05-10 14:32 ` [edk2-devel] " Carsey, Jaben
@ 2019-09-02 10:14   ` Heinrich Schuchardt
  2019-09-03  4:59     ` Nate DeSimone
  0 siblings, 1 reply; 5+ messages in thread
From: Heinrich Schuchardt @ 2019-09-02 10:14 UTC (permalink / raw)
  To: Carsey, Jaben, devel@edk2.groups.io, Gao, Zhichao
  Cc: Ni, Ray, Leif Lindholm, Gao, Liming, Stephano Cetola

On 5/10/19 4:32 PM, Carsey, Jaben wrote:
> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
>
> Code change looks good visually.

Somehow this patch

https://edk2.groups.io/g/devel/message/40395

was never merged.

Who is the maintainer for the ShellPkg?

Best regards

Heinrich

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

* Re: [edk2-devel] [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak
  2019-09-02 10:14   ` Heinrich Schuchardt
@ 2019-09-03  4:59     ` Nate DeSimone
  2019-09-03  7:14       ` Liming Gao
  0 siblings, 1 reply; 5+ messages in thread
From: Nate DeSimone @ 2019-09-03  4:59 UTC (permalink / raw)
  To: devel@edk2.groups.io, xypron.glpk@gmx.de, Carsey, Jaben,
	Gao, Zhichao
  Cc: Ni, Ray, Leif Lindholm, Gao, Liming, Stephano Cetola

From https://github.com/tianocore/edk2/blob/master/Maintainers.txt:

M: Jaben Carsey <jaben.carsey@intel.com>
M: Ray Ni <ray.ni@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Heinrich Schuchardt
Sent: Monday, September 2, 2019 3:15 AM
To: Carsey, Jaben <jaben.carsey@intel.com>; devel@edk2.groups.io; Gao, Zhichao <zhichao.gao@intel.com>
Cc: Ni, Ray <ray.ni@intel.com>; Leif Lindholm <leif.lindholm@linaro.org>; Gao, Liming <liming.gao@intel.com>; Stephano Cetola <stephano.cetola@linux.intel.com>
Subject: Re: [edk2-devel] [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak

On 5/10/19 4:32 PM, Carsey, Jaben wrote:
> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
>
> Code change looks good visually.

Somehow this patch

https://edk2.groups.io/g/devel/message/40395

was never merged.

Who is the maintainer for the ShellPkg?

Best regards

Heinrich




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

* Re: [edk2-devel] [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak
  2019-09-03  4:59     ` Nate DeSimone
@ 2019-09-03  7:14       ` Liming Gao
  0 siblings, 0 replies; 5+ messages in thread
From: Liming Gao @ 2019-09-03  7:14 UTC (permalink / raw)
  To: Desimone, Nathaniel L, devel@edk2.groups.io, xypron.glpk@gmx.de,
	Carsey, Jaben, Gao, Zhichao
  Cc: Ni, Ray, Leif Lindholm, Stephano Cetola, Gao, Liming

This patch has passed the package maintainer review. So, I push this change @8b8e91584555b6193f2099a36502763b47501533.

Thanks
Liming
>-----Original Message-----
>From: Desimone, Nathaniel L
>Sent: Tuesday, September 03, 2019 1:00 PM
>To: devel@edk2.groups.io; xypron.glpk@gmx.de; Carsey, Jaben
><jaben.carsey@intel.com>; Gao, Zhichao <zhichao.gao@intel.com>
>Cc: Ni, Ray <ray.ni@intel.com>; Leif Lindholm <leif.lindholm@linaro.org>; Gao,
>Liming <liming.gao@intel.com>; Stephano Cetola
><stephano.cetola@linux.intel.com>
>Subject: RE: [edk2-devel] [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL
>derefence and memory leak
>
>From https://github.com/tianocore/edk2/blob/master/Maintainers.txt:
>
>M: Jaben Carsey <jaben.carsey@intel.com>
>M: Ray Ni <ray.ni@intel.com>
>
>-----Original Message-----
>From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Heinrich
>Schuchardt
>Sent: Monday, September 2, 2019 3:15 AM
>To: Carsey, Jaben <jaben.carsey@intel.com>; devel@edk2.groups.io; Gao,
>Zhichao <zhichao.gao@intel.com>
>Cc: Ni, Ray <ray.ni@intel.com>; Leif Lindholm <leif.lindholm@linaro.org>; Gao,
>Liming <liming.gao@intel.com>; Stephano Cetola
><stephano.cetola@linux.intel.com>
>Subject: Re: [edk2-devel] [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL
>derefence and memory leak
>
>On 5/10/19 4:32 PM, Carsey, Jaben wrote:
>> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
>>
>> Code change looks good visually.
>
>Somehow this patch
>
>https://edk2.groups.io/g/devel/message/40395
>
>was never merged.
>
>Who is the maintainer for the ShellPkg?
>
>Best regards
>
>Heinrich
>
>


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

end of thread, other threads:[~2019-09-03  7:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-10  3:24 [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak Heinrich Schuchardt
2019-05-10 14:32 ` [edk2-devel] " Carsey, Jaben
2019-09-02 10:14   ` Heinrich Schuchardt
2019-09-03  4:59     ` Nate DeSimone
2019-09-03  7:14       ` Liming Gao

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