[edk2-devel] [PATCH v3 1/1] ShellPkg/CommandLib: avoid NULL derefence and memory leak
Carsey, Jaben
jaben.carsey at intel.com
Fri May 10 14:32:17 UTC 2019
Reviewed-by: Jaben Carsey <jaben.carsey at intel.com>
Code change looks good visually.
> -----Original Message-----
> From: devel at edk2.groups.io [mailto:devel at edk2.groups.io] On Behalf Of
> Heinrich Schuchardt
> Sent: Thursday, May 09, 2019 8:24 PM
> To: Gao, Zhichao <zhichao.gao at intel.com>
> Cc: devel @ edk2 . groups . io <devel at edk2.groups.io>; Carsey, Jaben
> <jaben.carsey at intel.com>; Ni, Ray <ray.ni at intel.com>; Leif Lindholm
> <leif.lindholm at linaro.org>; Gao, Liming <liming.gao at intel.com>; Heinrich
> Schuchardt <xypron.glpk at 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 at gmx.de>
> Reviewed-by: Zhichao Gao <zhichao.gao at 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 at edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub
> [jaben.carsey at intel.com]
> -=-=-=-=-=-=
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#40439): https://edk2.groups.io/g/devel/message/40439
Mute This Topic: https://groups.io/mt/31573312/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list